题解 | #某宝店铺动销率与售罄率#
某宝店铺动销率与售罄率
https://www.nowcoder.com/practice/715dd44c994f45cb871afa98f1b77538
select style_id,
round(sum(sales_num)/(max(a)-sum(sales_num))*100,2),
round(sum(sales_price)/max(b)*100,2)
from sales_tb left join
(select *,
sum(inventory)over(partition by style_id) a,
sum(tag_price*inventory)over(partition by style_id) b
from product_tb) as tb1
using(item_id)
group by style_id
order by style_id
#思路:
#①在表连接之前,把每种style的备货数量、备货金额用窗口函数算出来;
#②表连接,根据style_id分组,计算即可。
