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

各城市最大同时等车人数

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

select city,max(截止目前等车人数) as 最大值 from
(select city,
	    (sum(标识) over(partition by city order by event_time,标识 desc)) as 截止目前等车人数
        from
 ((select uid,
       city,
       event_time,
       1 as 标识
       from
       tb_get_car_record where date_format(event_time,'%Y-%m') = '2021-10') 
       UNION
       (select tb_get_car_order.uid,city,start_time,-1 as 标识
       from 
       tb_get_car_order join tb_get_car_record on tb_get_car_order.uid = tb_get_car_record.uid
       where date_format(event_time,'%Y-%m') = '2021-10')) a) b
       group by city
       order by 最大值,city;
全部评论

相关推荐

点赞 评论 收藏
分享
程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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