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

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

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

WITH t1 AS ( SELECT a.uid, driver_id, date( order_time ) AS order_time, mileage, grade, city FROM tb_get_car_order a LEFT JOIN tb_get_car_record b USING ( order_id ) ), t2 AS ( SELECT RANK() over ( PARTITION BY city ORDER BY round( sum( grade )/ count( grade ), 1 ) DESC ) AS rank_num, city, driver_id, round( sum( grade )/ count( grade ), 1 ) AS avg_grade, ROUND( count( order_time )/ count( DISTINCT order_time ), 1 ) AS avg_order_num, ROUND( sum( mileage )/ count( DISTINCT order_time ), 3 ) AS avg_mileage FROM t1 GROUP BY driver_id, city ) SELECT city, driver_id,avg_grade,avg_order_num,avg_mileage FROM t2 WHERE rank_num = 1 ORDER BY avg_order_num

全部评论

相关推荐

10-18 13:01
已编辑
西安理工大学 C++
小米内推大使:建议技能还是放上面吧,hr和技术面试官第一眼想看的应该是技能点和他们岗位是否匹配
点赞 评论 收藏
分享
11-14 16:13
已编辑
重庆科技大学 测试工程师
Amazarashi66:不进帖子我都知道🐮❤️网什么含金量
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务