读书人

这条SQL语句怎么写

发布时间: 2013-12-28 22:19:34 作者: rapoo

这条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表中不存在的数据

读书人网 >oracle

热点推荐