我没太懂你的意思,不知是不是这样:
由于 t2 记录的是 t1 的后一个月,因而想找一下增加的 id号。如果我理解正确就看下面代码,否则也不用看了。
select * from t2
where id not exists (select id from t1)
由于 t2 记录的是 t1 的后一个月,因而想找一下增加的 id号。如果我理解正确就看下面代码,否则也不用看了。
select * from t2
where id not exists (select id from t1)
where exist
(select 1 from t1 where t1.no = t2.no
and t1.id <> t2.id)
t1中有记录no=YS1001,id=522226;而t2中有
no=YS1001,id=522226和no=YS1001,id=36665。后一个记录是2月份新增加的。
我要找的是t2中YS1001,id=36665这个记录,也就是说同一个no和它对应的id有新增加 。
no id
YS1001 522226
YX1002 546666
t2
no id
YS1001 522226
YS1001 311115
YX1002 546666
我需要找出t2中YS1001 311115这个记录
where exists
(select 1 from t1 where t1.no = t2.no
and t1.id <> t2.id)