题解 | 目标月份的品类销售简报

目标月份的品类销售简报

https://www.nowcoder.com/practice/d5693e529a514ed390f097d395ad481d

大厂笔试SQL刷完了 祝我找份合适的工作

with t1 as(
    select category,count(distinct oi.order_id) orders_cnt,
    count(distinct buyer_id) buyers_cnt,
    sum(qty) items_qty,
    sum(qty*price) revenue,
    round(sum(qty*price)/count(distinct oi.order_id),2) avg_order_value
    from product p left join order_items oi on p.product_id = oi.product_id
    join orders o on oi.order_id = o.order_id
    where mid(order_date,1,7) = '2024-08'
    group by category
)
select category,orders_cnt,buyers_cnt,items_qty,revenue,avg_order_value,
rank()over(order by revenue desc,orders_cnt desc,category)  rank_by_revenue
from t1
order by revenue desc,orders_cnt desc,category

全部评论

相关推荐

2025-11-21 20:30
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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