[英]Conditional FROM statement Postgresql
我想根據條件查詢不同的表。 就像是:
select * FROM
case when :myvar = 'A' then
table A
when :myvar = 'B' then
table B
else
table C
end
編輯:所有表都有相同的列,但是:myvar 是外部設置的變量。 :myvar 不對應任何列中的值
如果所有表都具有相同的列,則使用union all
:
select a.*
from a
where :myvar = 'A'
union all
select b.*
from b
where :myvar = 'B'
union all
select c.*
from c
where :myvar not in ('A', 'B');
如果它們沒有相同的列,則來自所有表的select
通用列。 或者,放棄:單個select
查詢返回一組固定的列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.