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

帮忙望个SQL 排除查询

2013-04-12 
帮忙看个SQL 排除查询表AProID ProName UserType UserID-----------------------------1产品A101产品A

帮忙看个SQL 排除查询
表A

ProID ProName UserType UserID
-----------------------------
1     '产品A'  1        0
1     '产品A'  3        0
1     '产品A'  5        0


表B

ProID ProName UserType UserID
-----------------------------
1     '产品A'  1        0
1     '产品A'  3        0
1     '产品A'  5        0
1     '产品A'  0        27
1     '产品A'  0        33

要找出在表B中排除表A的数据.比较的字段是 ProID相同,UserType 和 UserID 同时不同

结果是
ProID ProName UserType UserID
-----------------------------
1     '产品A'  0        27
1     '产品A'  0        33


select * from 表B as B where ProID=1
and not exists
(
 select 1 from 表A where ProID=B.ProID and UserType=B.UserTye and UserID=B.UserID 
)



不知道是不是写错了,结果得不到?
[解决办法]
select * from t2 as B where ProID=1 and not exists 
(  select 1 from t1 where ProID=B.ProID and UserType=B.UserType and UserID=B.UserID  ) 
你的列名称没写对吧!
[解决办法]
UserType=B.UserTye
=>
UserType=B.UserType
[解决办法]

select b.* from 表B as B,表A as A where B.ProID=1
and  A.ProID=B.ProID and UserType<>B.UserTye and UserID<>B.UserID 
)

热点排行