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()) 
 )

解决方案 »

  1.   


    关系运算:差:
    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()) )
      

  2.   

    SELECT * FROM 表1 a
    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)
      

  3.   

    select * from 表1 as a WHERE NOT EXISTS 
     (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()) 
     )
      

  4.   

    SELECT a1,a2,a3 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())
      

  5.   

    除了以上条件,再把表1中的满足a3的条件:a3<>2 加上的记录查询出来,又应如何做?
      

  6.   

    加上后面的条件,查询语句为:
    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)对吧?