日期:2014-05-18 浏览次数:20468 次
select * from 商品表B b where not exists (select 1 from 销售表C c where b.goods=c.goods)
------解决方案--------------------
CREATE TABLE 客户表A ( customer VARCHAR(10) ) INSERT INTO 客户表A SELECT '张三' UNION SELECT '李四' UNION SELECT '王二麻子' CREATE TABLE 商品表B ( goods VARCHAR(10) ) INSERT INTO 商品表B SELECT '商品1' UNION SELECT '商品2' UNION SELECT '商品3' UNION SELECT '商品4' CREATE TABLE 销售表C ( customer VARCHAR(10), goods VARCHAR(10) ) INSERT INTO 销售表C SELECT '张三', '商品1' UNION SELECT '张三', '商品4' UNION SELECT '李四', '商品2' UNION SELECT '王二麻子', '商品3' UNION SELECT '王二麻子', '商品1' SELECT A.customer,B.goods FROM 客户表A AS A,商品表B AS B WHERE goods NOT IN (SELECT goods FROM 销售表C WHERE A.customer = 销售表C.customer)
------解决方案--------------------
[引用:]
select * from 商品表B b where not exists (select 1 from 销售表C c where b.goods=c.goods)