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

各城市最大同时等车人数

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

WITH total AS (
SELECT
city,
event_time AS dt,
1 AS tag

FROM tb_get_car_record 
RIGHT JOIN tb_get_car_order
USING(order_id)

UNION ALL

SELECT
city,
COALESCE(start_time, finish_time) AS dt,
-1 AS tag

FROM tb_get_car_record 
RIGHT JOIN tb_get_car_order
USING(order_id))

SELECT
city,
MAX(waiting_num) AS max_wait_uv

FROM(
SELECT
city,
SUM(tag) OVER(PARTITION BY city ORDER BY dt,tag DESC) AS waiting_num

FROM total

WHERE LEFT(dt, 7) = '2021-10') AS t1

GROUP BY city

ORDER BY max_wait_uv,city

全部评论

相关推荐

09-27 00:29
东北大学 Java
伟大的麻辣烫:查看图片
阿里巴巴稳定性 77人发布 投递阿里巴巴等公司10个岗位
点赞 评论 收藏
分享
10-14 23:01
已编辑
中国地质大学(武汉) Java
CUG芝士圈:虽然是网上的项目,但最好还是包装一下,然后现在大部分公司都在忙校招,十月底、十一月初会好找一些。最后,boss才沟通100家,别焦虑,我去年暑假找第一段实习的时候沟通了500➕才有面试,校友加油
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务