题解 | 每个商品的销售总额
每个商品的销售总额
https://www.nowcoder.com/practice/6d796e885ee44a9cb599f47b16a02ea4
with t as (select o.product_id, o.quantity, p.name, p.category from orders o inner join products p on o.product_id = p.product_id), t2 as (select name as product_name, sum(quantity) as total_sales from t group by product_name), t3 as (select * from t2 left join products p on t2.product_name = p.name) select product_name, total_sales, row_number() over (partition by category order by total_sales desc) as category_rank from t3