首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-04-25 
求简单ms-sql语句数据表A(dm,ztz,sj,xj),数据表B(dm1,ztz1,sj1,xj1),表B记录比A更多,求一句简单代码,检索

求简单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) 

热点排行