题解 | 每个商品的销售总额
每个商品的销售总额
https://www.nowcoder.com/practice/6d796e885ee44a9cb599f47b16a02ea4
with
t1 as(
select distinct
product_id,
name,
sum(quantity)over(partition by name order by name) as pcount,
category
from
orders left join products using(product_id)
)
,t2 as(
select
product_id,
name as product_name,
pcount as total_sales,
rank()over(partition by category order by pcount desc) as category_rank
from
t1
)
select product_name,total_sales,category_rank from t2 where product_name is not null

