请教这个SQL怎么写?多条件排除的查询!

xjbs 2003-09-01 10:23:46
表A:dept,goodscode,price
表B:dept,goodscode,spmprice//特价
现要将出现在表B中各部门的商品不出现在对表A的查询中
例:
Table A:
0001 a01 1.5
0001 a02 2.2
0001 a03 4.8
...
0002 a01 1.5
0002 a02 2.0
0002 a03 3.6
....
Table B:
0001 a03 3.6
0002 a01 3.8


写一个查询
要求结果是这样的:
dept goods price
0001 a01 1.5
0001 a02 2.2
0002 a02 2.0
0002 a03 3.6

help!!:)
...全文
531 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjbs 2003-09-01
  • 打赏
  • 举报
回复
大受启发,,;)
zarge 2003-09-01
  • 打赏
  • 举报
回复
select A.* from A left join B on A.dept = B.dept and A.goodscode = B.goodscode
where B.spmprice is null

OR

select * from A where not exists (select * from B where dept = A.dept and goodscode = A.goodscode)
liuyun2003 2003-09-01
  • 打赏
  • 举报
回复
乱舞好久不见了,在忙什么??
txlicenhe 2003-09-01
  • 打赏
  • 举报
回复
没太看懂。
pengdali 2003-09-01
  • 打赏
  • 举报
回复
select * from a where not exists(select 1 from b where dept=a.dept and goodscode=a.goodscode)
pengdali 2003-09-01
  • 打赏
  • 举报
回复
select * from a where not exists(select 1 from b where dept=a.dept and goodscode=a.goodscode)
pengdali 2003-09-01
  • 打赏
  • 举报
回复
select * from a where not exists(select 1 from b where dept=a.dept and goodscode=a.goodscode)
伍子V5 2003-09-01
  • 打赏
  • 举报
回复
select A.* from A,B where A.dept=B.dept and A.goods<>B.goods
愉快的登山者 2003-09-01
  • 打赏
  • 举报
回复
select * from 表A A where not exists (select * from 表B where dept = A.dept and goodscode = A.goodscode)
enhydraboy 2003-09-01
  • 打赏
  • 举报
回复
sorry,更正
==>
select a.dept,a.goods,a.price from A left outer join B on a.dept=b.dept and a.goods=b.goods
where b.price is null
enhydraboy 2003-09-01
  • 打赏
  • 举报
回复
sorry,更正
==>
select a.dept,a.goods,a.price from A left outer join B on a.dept=b.dept and a.goods=b.goods
where b.price is null
enhydraboy 2003-09-01
  • 打赏
  • 举报
回复
select a.dept,a.goods,a.price from A left outer join B on a.dept=b.dept and a.goods=b.goods
where b.price is not null
dafu71 2003-09-01
  • 打赏
  • 举报
回复
select tableA.* from tableA,tableB where tableA.dept=tableB.dept and tableA.goods<>tableB.goods

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧