题解 | 下单最多的商品

下单最多的商品

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

# 【问题】需要计算订单下单最多的商品id,取第一个返回即可;注最早支付的订单是只需要考虑order_log中的订单号的订单,非整条支付链路;相同次数以product_id顺序排列
# 问题粒度:product_id商品id
# user_client_log  粒度:trace_id+step
# product_info  粒度:product_id

select 
u.product_id
,sum(tmp_lab) as cnt
from 
(
    select 
    trace_id
    ,step
    ,case when step = 'order' then 1 else 0 end as tmp_lab
    ,product_id
    from user_client_log
    having step = 'order'
) u
left join product_info p
on u.product_id = p.product_id
group by u.product_id
order by cnt desc, product_id asc
limit 1

全部评论

相关推荐

不愿透露姓名的神秘牛友
05-22 16:32
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
03-29 08:32
点赞 评论 收藏
分享
头像
05-16 11:16
已编辑
东华理工大学 Java
牛客737698141号:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务