那举个例子说明一下 select * from t2 where not exists ( select 1 from t1 where no=t2.no and hm=t2.hm ) and exists ( select 1 from t1 where no=t2.no )
怎么结果不对!
试着这样看看,如果你不要求在一句话解决问题的话 把T1和T2插入一张临时表,然后把T1表和这个临时表进行我上面写的那样left join一下: select #temp.no, #temp.hm from #temp left join T1 on #temp.no= t1.no and #temp.hm=t1.hm where t1.no is null
Yang_(扬帆破浪) 是的可以用只要再加 1 < ALL (select count(*) from t2 two where t2.no = one.cardno)
>>对于一个no,t1,t2中都有,而且在t1或t2中记录不少于一个就行。假如t1中有三 >>条记录,t2中有一条,而且hm不存在t1中,这样的记录也符合查询条件。 ^^>> 1 < ALL ^^ >> (select count(*) from t2 two where t2.no = one.cardno) 不明白你说什么!!
YX0102 24449
YD0004 38888
除非:你在T2表中添加一个记录时间的字段或标识字段(id)
或着:等高手...
where noexists
(select no from table1 )
order by no
where not exists (
select 1 from t1
where no=t2.no and hm=t2.hm
)
and exists (
select 1 from t1
where no=t2.no
)
select t2.no, t2.hm from t2
left join t1
on t1.no= t2.no and t1.hm=t2.hm
where t1.no is null
那可就基本无解了,比如数据是
t1
no hm
YX0102 45668
YX0102 45678
YX0102 48888
t2
no hm
YX0102 45668
YX0102 45679
YX0102 48889
那样你根本不知道是修改了后两条(无结果),还是改了一条,增了一条,删了一条(结果一条),还是......这也是shinebei(灰灰) 一定要问是不是T2比T1多的原因,遗憾的是你未回答他的问题。要我说,以上各位的回答都对!!!
select * from t2
where not exists (
select 1 from t1
where no=t2.no and hm=t2.hm
)
and exists (
select 1 from t1
where no=t2.no
)
怎么结果不对!
把T1和T2插入一张临时表,然后把T1表和这个临时表进行我上面写的那样left join一下:
select #temp.no, #temp.hm from #temp
left join T1
on #temp.no= t1.no and #temp.hm=t1.hm
where t1.no is null
1 < ALL
(select count(*) from t2 two where t2.no = one.cardno)
>>条记录,t2中有一条,而且hm不存在t1中,这样的记录也符合查询条件。
^^>> 1 < ALL
^^
>> (select count(*) from t2 two where t2.no = one.cardno)
不明白你说什么!!