select C.* from C
left join (select cid,max(condate) condate from N group by cid) B C.id=B.cid 
where B.condate < convert(10,getdate()-15,120) or B.condate is null

解决方案 »

  1.   

    try
    Select A.* From 公司表 A 
    Where Not Exists(Select CID From 记录表 Where CID = A.CID And DateDiff(dd, ConData, GetDate()) <= 15)
      

  2.   

    select * from c
    where not exists (
    select 1 from n
    where cid=c.id
    and ConData>=dateadd(day,-15,getdate())
    )
      

  3.   

    select C.* from C,N where C.ID = N.CID and datediff(day,cast(ConData as datetime),getdate())>15
      

  4.   

    select C.* from C,N where C.ID = N.CID and datediff(day,cast(max(ConData) as datetime),getdate())>15