日期:2014-05-18 浏览次数:20719 次
--用一条SQL语句求出A,B的出库总量。 select mc,sum(s1) as total from tb_sell group by mc --用一条SQL语句求出A,B各剩下多少,要求显示产品名称。 select pname,s1-total from tb_product,(select mc,sum(s1) as total from tb_sell group by mc)tmp where tb_product.mc=tmp.mc --查询出A、B的库存总量和出库总量、显示在一个表中,要求显示产品名称 select * from tb_product inner join (select mc,sum(s1) as total from tb_sell group by mc)tmp on tb_product.mc=tmp.mc --------------------------------------------- mc total ---- ----------- A 333 B 1976 (2 行受影响) pname -------------------- ----------- 产品一 664 产品二 2567 (2 行受影响) mc pname s1 mc total ---- -------------------- ----------- ---- ----------- A 产品一 997 A 333 B 产品二 4543 B 1976 (2 行受影响)