题解 | 下单最多的商品

下单最多的商品

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 12:22
点赞 评论 收藏
分享
半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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