select * from old where not exists(select 1 from (select a.ksh,b.mc from new a left join Code b on a.ZYDM=b.ZYDM) tem where ksh=old.ksh and left(mc,2)=left(old.zydm,2))
不知道你为什么要substr,如果不要:select * from old where not exists(select 1 from (select a.ksh,b.mc from new a left join Code b on a.ZYDM=b.ZYDM) tem where ksh=old.ksh and mc=old.zydm)
declare @old int,@new int select @old=count(*) from old select @new=count(*) from old inner join (select ksh ,mc from new left join code on new.zydm=code.zydm) b on old.ksh=b.ksh and old.zydm=b.mc if(@old=@new) print '相同' else print '不相同'
select * from old where not exists(select * from (select a.ksh,b.mc from new a left join Code b on a.ZYDM=b.ZYDM) tem where ksh=old.ksh and left(mc,2)=left(old.zydm,2))
我在试验一下您提供得语句 好复杂啊 :) 又得半天学习了用substr是因为表1中ZYMC与表3中得专业名称不完全相同,如果选择精确匹配比较得话则表1中得大部分都不会相同,现在我想简化一下,只比较ZYMC得前几个字符。
select @old=count(*) from old
select @new=count(*) from old inner join (select ksh ,mc from new left join code on new.zydm=code.zydm) b
on old.ksh=b.ksh and old.zydm=b.mc
if(@old=@new)
print '相同'
else print '不相同'
待会我好好实践一下再结帐
太累了 困了pengdali(大力 V3.0)你可真热心,每次都是一有问题马上就能见到您得回答 谢谢