id riqi aa 2010.01.01 aa 2010.02.02 bb 2010.01.01 bb 2010.02.02 cc 2010.01.01
tb2
id riqi aa 2010.01.01 bb 2010.01.01 bb 2010.02.02
想要得到的结果为 id riqi aa 2010.02.02 cc 2010.01.01
没有唯一键 select * from tb1 where (id+cast(riqi as varchar)) not exists (select (rd+ cast(riqi as varchar)) ss from tb2) select * from tb1 where (id+cast(riqi as varchar)) not in (select (rd+ cast(riqi as varchar)) ss from tb2) select * from tb1 where (id+cast(riqi as varchar)) not exists (select (rd+ cast(riqi as varchar)) ss from tb2)===> select * from tb1 where (id+cast(riqi as varchar)) not in (select (rd+ cast(riqi as varchar)) ss from tb2) 2楼正解,not exists 换成 not in 也一样 这位老哥回帖好快。。。。。。 SQL code:
select * from tb1 t1 where not exists(select 1 from tb2 where id=t1.id and riqi=t1.riqi)
这年头 手慢了不行 想要的是 select max(riqi),id from tb1 group by id 这个不在tb2中的 网速快,机器好,能力强。 斗不过你们啊。。。。55555 都好快 {{----}