我有一个交易 list ,我需要检查它们是否存在于我的 DEALS
中。表,并且对于每个现有交易,从该表中显示其属性。
我使用该查询:
select * from deals
where run_id = 2550
and deal_id
in ('4385601', '4385602', ...);
但是,我也想知道该表中不存在哪些交易。我怎样才能做到这一点?
最佳答案
将所有交易记录放在单独的查找表中并使用它
select t2.*,
case when t1.deal_id is null then 'do not exist' else 'exists' end as status
from lookup_table as t1 left join deals as t2
on t1.deal_id=t2.deal_id
and t1.deal_id and t2.run_id = 2550
where ('4385601', '4385602', ...)
;
关于sql - 如何显示不存在的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31984206/