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

各城市最大同时等车人数

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

-- 各个城市,2021年10月期间,单日最大同时等车人数
with t1 as (select city,a.uid,event_time,
case when b.order_time is null then end_time 
when a.end_time = b.order_time and b.start_time is not null then b.start_time 
when a.end_time = b.order_time and b.start_time is null then b.finish_time else null end over_time
from tb_get_car_record a 
left join tb_get_car_order b
on a.uid = b.uid
and a.order_id = b.order_id
where substr(event_time,1,7) = '2021-10'
),
t2 as (select event_time dt from t1
union all
select over_time dt from t1)

select city,max(wait_uv) max_wait_uv from (select city,dt,count(distinct case when follow_num = 1 then uid else null end) wait_uv
from (select dt,city,uid,
case when t1.event_time > dt then 0 when t1.event_time <= dt and t1.over_time >= dt then 1 when t1.over_time < dt then 0 end follow_num
from t2 join t1) u 
group by city,dt) v 
group by city
order by max_wait_uv,city ASC

全部评论

相关推荐

沉淀一会:1.同学你面试评价不错,概率很大,请耐心等待; 2.你的排名比较靠前,不要担心,耐心等待; 3.问题不大,正在审批,不要着急签其他公司,等等我们! 4.预计9月中下旬,安心过节; 5.下周会有结果,请耐心等待下; 6.可能国庆节前后,一有结果我马上通知你; 7.预计10月中旬,再坚持一下; 8.正在走流程,就这两天了; 9.同学,结果我也不知道,你如果查到了也告诉我一声; 10.同学你出线不明朗,建议签其他公司保底! 11.同学你找了哪些公司,我也在找工作。
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务