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

各城市最大同时等车人数

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

SELECT
    city,MAX(uv) AS max_wait_uv
FROM
(
    SELECT
        city
        ,event_time
        ,COUNT(DISTINCT uid) AS uv
    FROM
    (
        SELECT
            t1.uid
            ,t1.city
            ,t1.event_time AS st 
            ,CASE WHEN t1.order_id=null THEN t1.end_time
                WHEN t2.start_time=null THEN t2.finish_time
                ELSE start_time END AS et
        FROM
            tb_get_car_record AS t1
        LEFT JOIN
            tb_get_car_order AS t2
        ON t1.order_id=t2.order_id
    )
    AS t1
    RIGHT JOIN
    (
        SELECT
        DISTINCT
        event_time
        FROM tb_get_car_record
    ) AS t2
    ON st<=event_time AND et>=event_time
    GROUP BY
        city
        ,event_time
    HAVING left(event_time,7)='2021-10'
) AS t1
GROUP BY
    city
ORDER BY
    max_wait_uv,city


全部评论

相关推荐

文物君i:感觉简历里经历好丰富,同27届想找实习,之前0经验,现在也找不到
实习简历求拷打
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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