日期:2014-05-16  浏览次数:20817 次

这条SQL语句如何写?
一个商品库存表
商品码itemid  库存数量stockqty

一个销售日结表
商品码itemid 销售数量qty

要查出有库存但是没有销量的商品信息
商品若是没有销售的话 不会存在销售日结表

------解决方案--------------------
引用:
Quote: 引用:

select * from t1 where t1.stockqty>0 and not exists(select 1 from t2 where t1.itemid=t2.itemid)

新手 有点不太明白 
能否解释下为什么子查询里 要select 1
你select * 或者字段 也是一样的
------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

select * from t1 where t1.stockqty>0 and not exists(select 1 from t2 where t1.itemid=t2.itemid)

新手 有点不太明白 
能否解释下为什么子查询里 要select 1
你select * 或者字段 也是一样的

那么子查询的条件就是关联字段么?

意思是:查询itemid在t2表中不存在的数据