您可以使用類似有條件的工會:
select ob1, ob2, q2."start", q2."end"
from (
select "start", "end", "max"
from the_table
) q1,
lateral (
select ob1, ob2, "start", "end"
from t1
where "max" < 10
union
select ob1, ob2, "start", "end"
from t2
where "max" >=10 and "max" < 50
union
select ob1, ob2, "start", "end"
from t3
where "max" >= 50
) q2
閱讀文檔中關於LATERAL Subqueries。
在Postgres的9.2可以使用with
查詢:
with m as (
select "max"
from the_table)
select ob1, ob2, q."start", q."end"
from (
select ob1, ob2, "start", "end"
from t1, m
where "max" < 10
union
select ob1, ob2, "start", "end"
from t2, m
where "max" >=10 and "max" < 50
union
select ob1, ob2, "start", "end"
from t3, m
where "max" >= 50
) q
最大的整數,開始和結束日期,OB1 ,ob2是整數... – Jayant