题解 | #每个商品的销售总额#
每个商品的销售总额
https://www.nowcoder.com/practice/6d796e885ee44a9cb599f47b16a02ea4
select name product_name,total_sales,category_rank from( select name,sum(quantity) total_sales,row_number() over(partition by category order by sum(quantity) desc,t1.product_id) category_rank from products t1 join orders t2 on t1.product_id=t2.product_id group by name,category,t1.product_id#group by 创建分组:注1:不能使用别名,原因可以去了解SQL的运行逻辑;注2:除聚集计算语句外,select语句中的每一列都必须在group by 子句中给出 order by category,sum(quantity) desc) t;

上海得物信息集团有限公司公司福利 1188人发布