1.查询出哪些商品从来没被购买过.
2.查询出哪些厂家的商品从来没被购买过.
3.统计出所有商品库存情况.
4.查询出食品类中哪些商品没被购买过.
5.
1.涉及到商品表和明细表
select distinct 商品名称
from 商品表 as t1
left outer join
明细表 as t2
on t1.商品ID=t2.商品ID
where t2.购买日期 is null
2.商品表,厂商表和明细表,把三个表连接起来,查出明细表字段哪个是空
select distinct 厂家名称 from 商品表 as t1
left outer join
厂家表 as t2 on t1.厂家ID=t2.厂家ID
left outer join
明细表 as t3 on t1.商品ID=t3.商品ID
where t3.购买日期 in null
3.商品ID,商品名称,入库量,库存量
商品表(入库量) 明细表(销售量)
select t1.商品ID,t1.商品名称,入库量,(入库量-innull(t2.出售数量,0) as '库存量' from 商品表 as t1
left outer join
(
select 商品ID,count(*) as '销售数量'
from 明细表
group by 商品ID
) as t2
on t1.商品ID=t2.商品ID