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

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

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

SELECT
	city,
	driver_id,
	avg_grade,
	avg_order_num,
	avg_mileage 
FROM
	(
	SELECT
		tr.city,
		bo.driver_id,
		round( sum( bo.grade ) / count( bo.grade ), 1 ) avg_grade,
		round(
			count( date_format( bo.order_time, "%Y-%m-%d" ) ) / count( DISTINCT date_format( bo.order_time, "%Y-%m-%d" ) ),
			1 
		) avg_order_num,
		round( sum( bo.mileage ) / count( DISTINCT date_format( bo.order_time, "%Y-%m-%d" ) ), 3 ) avg_mileage 
	FROM
		tb_get_car_order bo
		INNER JOIN tb_get_car_record tr ON bo.order_id = tr.order_id 
	GROUP BY
		bo.driver_id,
		tr.city 
	) M
	INNER JOIN (
	SELECT
		max( N.avg_grade ) mn,
		N.city mag 
	FROM
		(
		SELECT
			tr.city,
			round( sum( bo.grade ) / count( bo.grade ), 1 ) avg_grade 
		FROM
			tb_get_car_order bo
			INNER JOIN tb_get_car_record tr ON bo.order_id = tr.order_id 
		GROUP BY
			tr.city,
			bo.driver_id 
		) N 
	GROUP BY
		city 
	) T ON M.city = T.mag 
	AND M.avg_grade = T.mn
	ORDER BY avg_mileage
全部评论

相关推荐

oppo 应用软开 22*15+0.5*12
拿到了ssp完美:真的坎坷,但是你至少拿到这么多offer了!
点赞 评论 收藏
分享
实习挂完提前批挂_提前批挂完秋招挂:我是来结束这个秋招的😤
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务