题解 | 每个商品的销售总额
每个商品的销售总额
https://www.nowcoder.com/practice/6d796e885ee44a9cb599f47b16a02ea4
select product_name, total_sales, row_number()over(partition by category order by total_sales desc,product_id) as category_rank from( select orders.product_id, sum(quantity) as total_sales, category, name as product_name from orders join products on orders.product_id = products.product_id group by orders.product_id, products.category, products.name ) tmp
注意:
1 非聚合列都必须出现在 GROUP BY 子句中,select只能两种groupby字段和聚合
查看7道真题和解析
