题解 | 每个商品的销售总额

每个商品的销售总额

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字段和聚合

全部评论

相关推荐

1jian10:48h没写面评会变成这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务