从下表中我可以如何获得最近几天销售额> = 50%的商品?MySql查询:获取销售额> =特定百分比的商品
date item_id in_stock out-stock
2011-06-20 352 50 30
2011-06-21 351 10 1
2011-06-22 332 23 20
2011-06-23 311 12 7
目前我使用它计算销售比例的查询和使用PHP我正在通过循环每一个项目,并得到使用或销售的50%以上的项目。
SELECT i.id as item_id,i.item,SUM(dpr.out_stock)/SUM(dpr.in_stock) * 100 as p,SUM(dpr.out_stock) as sales,u.title as unit,u.id as unit_id
FROM `sm_daily_item_stock_report` as dpr
INNER JOIN sm_item_master as i on dpr.item_id=i.id and i.consumable='1'
INNER JOIN sm_unit_master as u on i.primary_unit=u.id
WHERE date between '2011-06-20' and '2011-06-23'
and dpr.store_id='1' GROUP BY item_id
但这查询返回的所有产品对STORE_ID 1
Krishnik
2011-06-24
Nick