题解 | #各城市最大同时等车人数#
各城市最大同时等车人数
https://www.nowcoder.com/practice/f301eccab83c42ab8dab80f28a1eef98
with t1 as( select tbd.uid,city,event_time,start_time from tb_get_car_record tbd left join tb_get_car_order tbo on tbd.order_id = tbo.order_id where date_format(event_time,"%Y-%m") = "2021-10" ) select city,max(wait_uv) as max_wait_uv from( select city,sum(uv)over(partition by city order by time,uv desc) as wait_uv from ( select city,event_time as time,1 as uv from t1 union all select city,start_time as time,-1 as uv from t1 ) t2 ) t3 group by city order by max_wait_uv
第一步:连接表 筛选2021-10月份的数据
第二步:联合查询 下单时间 和接上车时间 因为等待时间就是从下单到下单成功 下单成功到接上车 合并一下
第一过程记为1 第二过程记为-1
第三步:使用聚合函数 累加 根据城市分组,按照时间升序 uv降序
第四步:筛选出最大的