我的情况看起来像这样 - 我正在使用postgres数据库,ERP应用程序有大量的SQL查询,我甚至不能把这个查询放在这里,但这不是问题,我只需要一个建议。
就像是:
SELECT data FROM g.table
CASE WHEN data=0
THEN leave it as it is
WHEN data=1
THEN get data from h schema
是否有可能?一些功能可能或其他解决方案?谢谢
你的问题很模糊,所以我的答案也是:
SELECT CASE g."table".data
WHEN 0 THEN g."table".data
WHEN 1 THEN h."table".data
END
FROM g."table"
CROSS JOIN h."table";
我想你想要一个更像这样的结构:
select g.*
from g
where g.col = 0
union all
select h.*
from h
where exists (select 1 from g where g.? = h.? and g.col = 1);