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

各城市最大同时等车人数

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

WITH grouped_dt as(
SELECT  city
    ,event_time uv_time
    ,1 diff
FROM tb_get_car_record
UNION ALL
SELECT city
    ,end_time
    ,-1
FROM tb_get_car_record
WHERE order_id is null
UNION ALL
SELECT city
    ,finish_time
    ,-1
FROM tb_get_car_order
LEFT JOIN tb_get_car_record
ON tb_get_car_order.order_id = tb_get_car_record.order_id
WHERE order_time is not null
AND start_time is null
UNION ALL
SELECT city
    ,start_time
    ,-1
FROM tb_get_car_order
LEFT JOIN tb_get_car_record
ON tb_get_car_order.order_id = tb_get_car_record.order_id
WHERE order_time is not null
AND start_time is not null
),
sum_dt as(
SELECT city
    ,sum(diff)over(partition by city order by uv_time,diff desc) sum_uv
FROM grouped_dt
WHERE date_format(uv_time,'%Y%m')='202110'
)
SELECT city
    ,max(sum_uv) max_wait_uv
FROM sum_dt 
GROUP BY city
ORDER BY max_wait_uv,city




全部评论

相关推荐

哞客37422655...:github如果提交不是很多 可以不写 可能会是减分项。之前听别人讲过的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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