当前位置: 代码迷 >> VFP >> 求SQL语句,统计商品的净卖出量。多谢
  详细解决方案

求SQL语句,统计商品的净卖出量。多谢

热度:8550   发布时间:2013-02-26 00:00:00.0
求SQL语句,统计商品的净卖出量。谢谢!
现有商品p1,p2,有一表记录一个月来的买入和卖出的数量。
Product BS Quantity

P1 B 100
P1 B 200
P1 S 500
p2 B 400
p2 S 900
P2 S 100

现在想统计每个产品这个月来的净卖出量。希望得到这样的结果:
P1 200 //500-200-100
p2 600 //900+100-400

多谢各位~

------解决方案--------------------------------------------------------
select Product,sum(iif(BS="B",-Quantity,Quantity)) as Quantity from cTableName group by Product
------解决方案--------------------------------------------------------
select Product, sum(iif(BS='S',1,-1)*Quantity) as qty from 销售记录表 group by Product
  相关解决方案