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
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
Select A.* From 公司表 A
Where Not Exists(Select CID From 记录表 Where CID = A.CID And DateDiff(dd, ConData, GetDate()) <= 15)
where not exists (
select 1 from n
where cid=c.id
and ConData>=dateadd(day,-15,getdate())
)