select * from 表1 as a
WHERE NOT EXISTS (select * from 表2 as b
where a.a1=b.b1 and a.a2=b.b2 and year(b.b3)=year(getdate()) and month(b.b3)=month(getdate())
)
WHERE NOT EXISTS (select * from 表2 as b
where a.a1=b.b1 and a.a2=b.b2 and year(b.b3)=year(getdate()) and month(b.b3)=month(getdate())
)
关系运算:差:
c1-c2:select * from t1 where not exists(select 1 from t2 where t1.c1=t2.c1 and t1.c2=t2.c2)c2-c1:select * from t2 where not exists(select 1 from t1 where t1.c1=t2.c1 and t1.c2=t2.c2)SELECT * FROM 表1 a
WHERE NOT EXISTS
( SELECT 1 FROM 表2 b WHERE a.a1=b.b1 AND a.a2=b.b2 AND YEAR (b.b3)=YEAR(getdate()) AND MONTH (b.b3)= MONTH(getdate()) )
WHERE NOT EXISTS
( SELECT 1 FROM 表2 b WHERE a.a1=b.b1 AND a.a2=b.b2 AND convert(char(8),b.b3,112)=convert(char(8),getdate(),112)
(select * from 表2 where b1=a.a1 and b2=a.a2
and datepart(year,b3)=datepart(year,getdate())
and datepart(month, b3)=datepart(month, getdate())
)
WHERE NOT EXISTS
( SELECT 1 FROM 表2 b where a.a1=b.b1 and a.a2=b.b2 and year(b.b3)=year(getdate()) and month(b.b3)=month(getdate())
select * from 表1 as a
WHERE NOT EXISTS (select * from 表2 b ,表1 c
where c.a1=b.b1 and c.a2=b.b2 and year(b.b3)=year(getdate()) and month(b.b3)=month(getdate()) and c.b3<>2)对吧?