题解 | #有取消订单记录的司机平均评分#

有取消订单记录的司机平均评分

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

select if(grouping(driver_id)=0,driver_id,'总体'),
round(avg(grade),1)
from tb_get_car_order 
where grade is not null -- 2、有评价的订单
and 
driver_id in (select distinct driver_id from tb_get_car_order where left(date(order_time),7)='2021-10' and start_time is null) -- 1、2021-10月中有过取消订单的司机
group by driver_id with rollup

1、思路

一、首先找到2021-10月中有过取消订单的司机

SELECT DISTINCT driver_id

FROM tb_get_car_order

WHERE left(date(order_time),7)='2021-10' and start_time is null

二、找到这些司机的所有有评价的订单

即 tb_get_car_order 中 driver_id in()grade is not null

三、对这些订单根据司机求平均分

2、函数使用

group by xxx with rollupgrouping

全部评论

相关推荐

07-15 00:33
江苏大学 Java
代码飞升:哈哈哈哈评论区三个打广告的
简历中的项目经历要怎么写
点赞 评论 收藏
分享
门口唉提是地铁杀:之前b站被一个游戏demo深深的吸引了。看up主页发现是个初创公司,而且还在招人,也是一天60。二面的时候要我做一个登录验证和传输文件两个微服务,做完要我推到github仓库,还要我加上jaeger和一堆运维工具做性能测试并且面试的时候投屏演示。我傻乎乎的做完以后人家跟我说一句现在暂时不招人,1分钱没拿到全是白干
你的秋招第一场笔试是哪家
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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