MySQL如何计算动销率_20161025
动销率一般反映在采购管理上,它的公式为:商品动销率=(动销品种数 /仓库总品种数)*100% 。
也可以理解为销售的商品数量和仓库库存的商品数量,假如你仓库里有100个品种,在上月销售了50种,动销率=50/100*100%=50%
这里我们有两个表,一个是库存表一个是订单销售表。
SELECT c.*,d.库存商品数,c.销售商品数/d.库存商品数 AS 动销率 FROM (#各城市各月销售商品数 SELECT b.城市,b.年月,COUNT(b.商品ID) AS 销售商品数 FROM ( SELECT a.city AS 城市,a.`productID` AS 商品ID,DATE_FORMAT(a.`order_date`,"%Y%m") AS 年月 FROM `test_a03order` AS a#订单表 GROUP BY a.city ,a.`productID` ,DATE_FORMAT(a.`order_date`,"%Y%m") ) AS b GROUP BY b.城市,b.年月 ) AS c LEFT JOIN (#各城市各月库存商品数 SELECT b.城市,b.年月,COUNT(b.商品ID) AS 销售商品数 FROM ( SELECT a.city AS 城市,a.`productID` AS 商品ID,DATE_FORMAT(a.`date`,"%Y%m") AS 年月 FROM `test_a05order` AS a#库存表 GROUP BY a.city ,a.`productID` ,DATE_FORMAT(a.`date`,"%Y%m") ) AS b GROUP BY b.城市,b.年月 ) AS d ON c.城市=d.城市 AND c.年月=d.年月