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

各城市最大同时等车人数

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

select 
    city,
    max(num) as max_wait_uv
from(    
    select 
        city,
        sum(uv) over (partition by city,date(dt) ORDER BY dt asc, uv DESC) as num
    from(
        select 
            city,
            event_time as dt,
            order_id,
            1 as uv
        from 
            tb_get_car_record
        where 
            left(event_time,7) = '2021-10'
        union all
        select
            city,
            start_time as dt,
            order_id,
            -1 as uv
        from 
            tb_get_car_order as a
        left join tb_get_car_record as b
        using(order_id)
        where 
            left(start_time,7) = '2021-10'
        union all
        select
            city,
            finish_time as dt,
            order_id,
            -1 as uv
        from 
            tb_get_car_order as a
        left join tb_get_car_record as b
        using(order_id)
        where 
            left(finish_time,7) = '2021-10') as t) as t1
group by 1
order by max_wait_uv asc,city asc

全部评论

相关推荐

海螺很能干:每次看到这种简历都没工作我就觉得离谱
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务