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

各城市最大同时等车人数

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

with zb as (with cb2 as ((with cb as (select city,event_time,1 as wait_nu,if(start_time is not null,start_time,end_time) end_time,-1 as leave_num 
/*将开始打车时间点标记为1,结束为-1,如果没有接单则以打车结束时间当作结束等待时间*/
from tb_get_car_order tgo
left join tb_get_car_record tgr on tgo.order_id= tgr.order_id /*左连接,要取到所有打车信息*/
where event_time like '2021-10%')
select city,event_time,wait_nu
from cb
union all 
select city,end_time,leave_num
from cb
order by event_time))
select city,date(event_time) time_day,event_time,
sum(wait_nu) over(partition by city,date(event_time) order by event_time,wait_nu desc) wait_uv /*个时间段等待人数*/
from cb2)
select city,max(wait_uv) as max_wait_uv
from zb
group by city
order by max_wait_uv,city

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-21 17:16
科大讯飞 算法工程师 28.0k*14.0, 百分之三十是绩效,惯例只发0.9
点赞 评论 收藏
分享
11-15 18:39
已编辑
西安交通大学 Java
全村最靓的仔仔:卧槽,佬啥bg呢,本也是西交么
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务