首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

这条SQL语句怎么写

2013-12-28 
这条SQL语句如何写?一个商品库存表商品码itemid库存数量stockqty一个销售日结表商品码itemid 销售数量qty

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

热点排行