您的位置:首页 > 其它

exists ,not exists改写成in 和 not in 时,要注意null值的情况,会影响结果

2015-08-30 12:54 471 查看
---not exists

select count(distinct a.pos_mer_id)

from tests a

where a.stat_flag='C' and not exists

(select 1 from

hfods.tests b

where b.stat_flag='N' and b.pos_mer_id=a.pos_mer_id);

改写成not in

select count(distinct a.pos_mer_id)

from tests a

where a.stat_flag='C' and a.pos_mer_id not in

(select b.pos_mer_id from

tests b

where b.stat_flag='N' and b.pos_mer_id is not null)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: