两张表tb1id riqi
aa 2010.01.01
aa 2010.02.02
bb 2010.01.01
bb 2010.02.02
cc 2010.01.01tb2id riqi
aa 2010.01.01
bb 2010.01.01
bb 2010.02.02想要得到的结果为
id riqi
aa 2010.02.02
cc 2010.01.01
aa 2010.01.01
aa 2010.02.02
bb 2010.01.01
bb 2010.02.02
cc 2010.01.01tb2id 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 in (select (rd+ cast(riqi as varchar)) ss from tb2)
select * from tb1 t1 where not exists(select 1 from tb2 where id=t1.id and riqi=t1.riqi)
select id,max(riqi) from (select * from tb1 t1 where not exists(select 1 from tb2 where id=t1.id and riqi=t1.riqi))t group by t.id
(id+cast(riqi as varchar)) 这是啥意思 不懂 给讲讲呗
这是把riqi转换成字符串形式,其实这里完全不需要,你数据库里头riqi本身就是字符串的