当前位置: 代码迷 >> Sql Server >> 求简单ms-sql语句,该怎么处理
  详细解决方案

求简单ms-sql语句,该怎么处理

热度:36   发布时间:2016-04-27 13:28:00.0
求简单ms-sql语句
数据表A(dm,ztz,sj,xj),数据表B(dm1,ztz1,sj1,xj1),表B记录比A更多,求一句简单代码,检索出表A和B对应字段不相等所有记录,即使dm!=dm1或ztz!=ztz1或sj!=sj1或xj!=xj1 的所有记录。

------解决方案--------------------
SQL code
--dm,ztz,sj,xjselect * from bexceptselect * from a--如果b包含a,可以select *from b twhere not exists (select 1 from a where dm=t.dm and ztz=t.ztz and sj=t.sj and xj=t.xj)--如果b和a不是互相包含的select *from b twhere not exists (select 1 from a where dm=t.dm and ztz=t.ztz and sj=t.sj and xj=t.xj)unionselect *from a twhere not exists (select 1 from b where dm=t.dm and ztz=t.ztz and sj=t.sj and xj=t.xj)
  相关解决方案