表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!!:)
13 个解决方案
#1
select tableA.* from tableA,tableB where tableA.dept=tableB.dept and tableA.goods<>tableB.goods
#2
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
where b.price is not null
#3
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
==>
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
#4
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
==>
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
#5
select * from 表A A where not exists (select * from 表B where dept = A.dept and goodscode = A.goodscode)
#6
select A.* from A,B where A.dept=B.dept and A.goods<>B.goods
#7
select * from a where not exists(select 1 from b where dept=a.dept and goodscode=a.goodscode)
#8
select * from a where not exists(select 1 from b where dept=a.dept and goodscode=a.goodscode)
#9
select * from a where not exists(select 1 from b where dept=a.dept and goodscode=a.goodscode)
#10
没太看懂。
#11
乱舞好久不见了,在忙什么??
#12
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)
where B.spmprice is null
OR
select * from A where not exists (select * from B where dept = A.dept and goodscode = A.goodscode)
#13
大受启发,,;)
#1
select tableA.* from tableA,tableB where tableA.dept=tableB.dept and tableA.goods<>tableB.goods
#2
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
where b.price is not null
#3
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
==>
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
#4
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
==>
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
#5
select * from 表A A where not exists (select * from 表B where dept = A.dept and goodscode = A.goodscode)
#6
select A.* from A,B where A.dept=B.dept and A.goods<>B.goods
#7
select * from a where not exists(select 1 from b where dept=a.dept and goodscode=a.goodscode)
#8
select * from a where not exists(select 1 from b where dept=a.dept and goodscode=a.goodscode)
#9
select * from a where not exists(select 1 from b where dept=a.dept and goodscode=a.goodscode)
#10
没太看懂。
#11
乱舞好久不见了,在忙什么??
#12
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)
where B.spmprice is null
OR
select * from A where not exists (select * from B where dept = A.dept and goodscode = A.goodscode)
#13
大受启发,,;)