SELECT *
FROM   a
WHERE  NOT EXISTS
       (
       SELECT * FROM b
       WHERE  items=a.items 
              AND invs=a.invs
              AND DatePart(month,create_date)=DatePart(month,Getdate())
              AND DatePart(year,create_date)=DatePart(year,Getdate())
      )
 

解决方案 »

  1.   

    --??
    set nocount on
    declare @ta table(items int ,  invs int ,    total int) 
    insert @ta select 771, 9 ,35000 
    insert @ta select 845, 1, 2560 
    insert @ta select 771, 1, 44000 
    insert @ta select 863, 1, 1500 
    declare @tb table (items int,  invs int ,    total int,   create_date datetime) 
    insert @tb select 771,      9,      8000,    '2008-09-01' 
    insert @tb select 771,      9,      10000,  '2008-10-12' 
    select distinct a.* from @ta a inner join @tb b on a.items=b.items and a.invs<>b.invs
    /*
    items       invs        total       
    ----------- ----------- ----------- 
    771         1           44000
    */
      

  2.   


    select * from A t
    where not exists (select 1 from B where items=t.items and invs=t.invs)