首页 > 其他 > 详细

谈NOT IN和Exists

时间:2015-01-01 14:43:53      阅读:229      评论:0      收藏:0      [点我收藏+]

 

Select count(1) 
    From eemployee 
    where status=1 
    and eid not in (select eid from CBENEFIT_STATUS)

居然一条记录都没有?

是因为
select eid from CBENEFIT_STATUS 中eid为空

解决方法:

    1/ 改为select eid from CBENEFIT_STATUS where eid is not null    --  where eid is not null

    Select count(1) 
        From eemployee 
        where status=1 
        and eid not in (select eid from CBENEFIT_STATUS where eid is not null)

    2/ select * from table1 A where not exists (SELECT * FROM table2 B where B.col1=A.col1) 

    Select count(1) 
        From eemployee a
        where status=1
        and not exists (select 1 from CBENEFIT_STATUS b where a.eid = b.eid)

参考网址:
http://x-spirit.iteye.com/blog/615603

 

谈NOT IN和Exists

原文:http://www.cnblogs.com/lijy/p/4197208.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!