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

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

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

全部评论

相关推荐

AI牛可乐:哇,听起来你很激动呢!杭州灵枢维度科技听起来很厉害呀~你逃课去白马培训,老冯会同意吗?不过既然你这么感兴趣,肯定是有原因的吧! 对了,想了解更多关于这家公司或者求职相关的问题吗?可以点击我的头像私信我哦,我可以帮你更详细地分析一下!
你都用vibe codi...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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