一开始没能明白啥事SPU有销售和在售的意思,后来看了大家的解释知道是 售出数/库存剩余,才明白了意思 唯一值得注意的就是,在计算product_tb中的库存和库存代换金额的时候,因为关联导致的多行,不能直接求和,需要除一下行数
``` select style_id,round((sum(already_sale)/sum(not_sale))*100,2) as `pin_rate(%)`,
round((sum(total_sale)/sum(total_tag))*100,2) as `sell-through_rate(%)`
from (select style_id,item_id,
sum(sales_num) as already_sale,
sum(inventory)/count(1) - sum(sales_num) as not_sale,
ifnull(sum(sales_price),0) as total_sale,
sum(tag_price*inventory)/count(1) as total_tag
from sales_tb b
right join product_tb a using(item_id)
group by 1,2
) a
group by 1
order by 1

京公网安备 11010502036488号