select * from 表 a where fyear=2003 and fmonth=2 and
 not exists(select 1 from 表 where fyear=2003 and fmonth=1 and a.fbillid=fbillid and a.fempid=fempid)

解决方案 »

  1.   

    declare @ table (fyear int,fmonth int,fbillid int,fempid int)
    insert @ values(2003,  1,      1 ,      1)
    insert @ values(2003,  1,      2,       1)
    insert @ values(2003 , 1,      3 ,      1)
    insert @ values(2003 , 1,      4  ,     1 )  
    insert @ values(2003 , 2,      1   ,    1)
    insert @ values(2003 , 2,      2    ,   1)
    select * from @ a where fyear=2003 and fmonth=1 and not exists(select 1 from @ where fyear=2003 and fmonth=2 and a.fbillid=fbillid and a.fempid=fempid)--还是:select * from @ a where fyear=2003 and fmonth=2 and not exists(select 1 from @ where fyear=2003 and fmonth=1 and a.fbillid=fbillid and a.fempid=fempid)
      

  2.   

    不太理解你的意思。select * from table where fyrear = '2003' and fmonth = '1' and fbillid not in (select fbillid from table where fyrear = '2003' and fmonth = '2')
      

  3.   

    select * from @ a where fyear=2003 and fmonth=2 and not exists(select 1 from @ where fyear=2003 and fmonth=1 and a.fbillid=fbillid and a.fempid=fempid)