题解 | 每个商品的销售总额
每个商品的销售总额
https://www.nowcoder.com/practice/6d796e885ee44a9cb599f47b16a02ea4
SELECT
name product_name,
total_sales,
row_number() over (
partition by
category
order by
total_sales desc,p.product_id asc
) category_rank
from
products p
left join (
SELECT
product_id,
sum(o.quantity) total_sales
from
orders o
group by
product_id
) a on p.product_id = a.product_id
where total_sales is not null
order by
category asc,total_sales desc,p.product_id asc;
查看29道真题和解析