码迷,mamicode.com
首页 > 其他好文 > 详细

谈NOT IN和Exists

时间:2015-01-01 14:46:11      阅读:131      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!