在下面的查询中,如何执行查询
其中,如果tbl3.CID存在于tbl1.ID中,或tbl3.CID存在于tbl2.ID中,其中警报<> '',
然后“确认”否则“输出”最终结果?
select * from tbl3, tbl4 where tbl3.type = tbl4.name and tgl4.GroupName <> 'abc'
tbl1
ID Prime_Number
1 1-11
1 1-22
2 2-11
tbl2
ID Alert
1 NULL
2 NULL
3 XOM
tbl3
CID Sales
1 100
3 200
4 300
tbl4
Name GroupName
CORP Corporates
INTL International预期结果
Result CID Sales
CONFIRM 1 100 --> from tbl1
CONFIRM 3 200 --> from tbl2
OUT 4 300发布于 2019-12-11 04:37:07
脑海中浮现出exists:
select t3.*,
(case when exists (select 1 from tbl1 t1 where t1.id = t3.cid)
then 'CONFIRM'
when exists (select 1 from tbl2 t2 where t2.id = t3.cid and t2.alert is not null)
then 'CONFIRM'
else 'OUT'
end) as result
from table3 t3;https://stackoverflow.com/questions/59274793
复制相似问题