题解 | 下单最多的商品

下单最多的商品

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

全部评论

相关推荐

01-03 12:06
复旦大学 Java
点赞 评论 收藏
分享
2025-12-16 17:17
门头沟学院 产品经理
烤点老白薯:他第二句话的潜台词是想让你帮他点个瑞幸或者喜茶啥的
mt对你说过最有启发的一...
点赞 评论 收藏
分享
专业嗎喽:个人信息名字太大,合到电话邮箱那一栏就行,有党员写过党,剩下其他全删,站空太大了 把实习经历丰富,放最前面,然后是个人评价,技能之类的,然后是学校信息。项目经历最后面,可以就选一个自己擅长的。 现在是学校不是92就扣分的,没必要放前面。 然后现在看重实习经历>竞赛经历(校园经历)>课程项目经历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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