例如:
結果集A等于 select id from X;
結果集B等于 select id from Y;
sql陳述句如下:
select * from Z where z.id in(這里如果A不為空就是 select id from X;如果A為空就是select id from Y)
其中結果集A和B都有可能是多個值。目的就是實作當結果集A一條資料都沒有的時候,就選擇結果集B。
請教這樣的情況該如何寫SQL陳述句能實作。
最好是Oracle標準下的。
謝謝
uj5u.com熱心網友回復:
select * from Z where z.id in(nvl(A,B)) ???uj5u.com熱心網友回復:
select * from test3 where id in (select id from test1 union select id from
test2,(select count(1) count from test1) where count=0);
uj5u.com熱心網友回復:
select * from Z where z.id in (select id from X)
UNION
select * from Z where z.id in (select id from Y WHERE 0 = (SELECT COUNT(ID) FROM X))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/92149.html
標籤:開發
下一篇:請教大神
