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