读书人

求一条SQL,应该简单,但写不来

发布时间: 2013-04-09 16:45:09 作者: rapoo

求1条SQL,应该简单,但写不来.
表A
c_id c_date
001 2010-01-01
001 2010-01-02
001 2010-01-03
002 2010-01-01
002 2010-01-02
002 2010-01-03

表B
c_id c_date
001 2010-01-01
001 2010-01-03
002 2010-01-01
002 2010-01-02
--------------------------------
期望的结果(即A表有,B表没用的数据)
要求,不能用2个NOT IN 的方法.
c_id c_date
001 2010-01-02
002 2010-01-03

[解决办法]
参考:
http://www.cnblogs.com/aierong/archive/2008/08/25/1273831.html
[解决办法]

引用:
SQL code?123 select a.* from a left join b on a.c_id = b.c_id and a.c_date = b.c_date where a.c_id is null

修改成

select a.*
from a left join b on a.c_id = b.c_id and a.c_date = b.c_date
where b.c_id is null

读书人网 >SQL Server

热点推荐