题解 | #每个商品的销售总额#
每个商品的销售总额
https://www.nowcoder.com/practice/6d796e885ee44a9cb599f47b16a02ea4
SELECT A.name AS product_name, SUM(B.quantity) AS total_sales, RANK() OVER ( partition BY A.category ORDER BY SUM(B.quantity) DESC ) AS category_rank FROM products A JOIN orders B ON A.product_id = B.product_id GROUP BY B.product_id