题解 | #每个城市中评分最高的司机信息#

每个城市中评分最高的司机信息

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

select 
f.city,
f.driver_id,
format(avg_socre,1) avg_grade,
format(count(e.order_id)/count(distinct date_format(e.order_time,'%Y%m%d')),1) avg_order_num,
format(sum(e.mileage)/count(distinct date_format(e.order_time,'%Y%m%d')),3) avg_mileage
from 
tb_get_car_order e,
(
	select 
	*
	from (
		select
		*,
		rank() over(partition by city order by avg_socre desc) ranking 
		from 
		(
		    select
		    a.city,b.driver_id,avg(grade) avg_socre
		    from 
		    tb_get_car_record a,tb_get_car_order b
		    where a.order_id=b.order_id
		    group by a.city,b.driver_id
		) c
	) d
	where ranking=1
) f
where e.driver_id=f.driver_id
group by f.city,f.driver_id
order by avg_order_num asc

全部评论

相关推荐

香梨想要offer:人手一个muduo
点赞 评论 收藏
分享
牛客263158796号:我领羊一面后十天不挂也不推进 今天问hr说等前序的第一批意向发完看情况再看是否推进
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务