题解 | #各城市最大同时等车人数#

各城市最大同时等车人数

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

with t1 as
(
    select city,event_time as tm,1 as outin
    from tb_get_car_record
    union all
    select city,case 
    when order_id is null then end_time #用户取消订单/没司机接单
    when start_time is null then finish_time #用户或取消订单
    else start_time end as ft,-1
    from tb_get_car_record
    left join tb_get_car_order using(order_id)#可能出现无订单号的情况
)
select city,max(pku)
from
(
select city,tm,sum(outin) over(order by tm asc,outin desc) as pku #先计算用户增加
from t1
where substr(tm,1,7)='2021-10'
)t
group by city,date(tm) #城市单日订单峰值

全部评论

相关推荐

认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的开发你这个也没有项目啊
点赞 评论 收藏
分享
06-27 15:15
长安大学 Java
哈哈哈,你是老六:这种就是培训机构骗钱的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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