很简单的SQL语句问题(10)

  • 主题发起人 主题发起人 多多帮助
  • 开始时间 开始时间

多多帮助

Unregistered / Unconfirmed
GUEST, unregistred user!
select 商品编号, sum(进货数量) AS 进货数量, sum(进货金额) AS 进货金额 from 进货表怎么加个进货均价
 
不会是灌水吧?select 商品编号, sum(进货数量AS 进货数量, sum(进货金额) AS 进货金额,sum(进货数量)/sum(进货金额) AS 进货均价 from 进货表
 
不是灌水这样不行吗?select 商品编号, sum(进货数量)AS 进货总数量, sum(进货金额) AS 进货总金额,(进货总数量/进货总金额) AS 进货均价 from 进货表
 
这样不行,因为进货表里没有 进货总数量 和 进货总金额 这两栏
 
select a.商品编号, ISNULL(b.进货数量, 0) 进货数量, ISNULL(b.进货金额, 0) AS 进货金额, ISNULL(c.销售数量, 0) AS 销售数量, ISNULL(c.销售金额, 0) AS 销售金额 from 商品表 LEFT OUTER JOIN (select 商品编号, sum(进货数量) AS 进货数量, sum(进货金额) AS 进货金额 from 进货表 group by 商品编号) b ON a.商品编号=b.商品编号 LEFT OUTER JOIN (select 商品编号, sum(销售数量) as 销售数量,sum(销售金额) as 销售金额 from 销售表 group by 商品编号) C on a.商品编号=c.商品编号怎么改成计算成本金额?多谢
 
后退
顶部