题解 | 每个商品的销售总额
SELECT product_name, total_sales, ROW_NUMBER() OVER (PARTITION BY category ORDER BY total_sales DESC, a.product_id) AS category_rank
FROM(SELECT DISTINCT o.product_id, name AS product_name, category,
SUM(quantity) OVER(PARTITION BY o.product_id) AS total_sales
FROM orders o
INNER JOIN products p ON o.product_id = p.product_id
) a
ORDER BY category, total_sales DESC;
顺丰集团工作强度 322人发布