sql174 | 2021年国庆在北京接单3次以上的司机数据

2021年国庆在北京接单3次及以上的司机统计信息

https://www.nowcoder.com/practice/992783fd80f746d49e790d33ee537c19

#需求:统计2021年国庆7天期间在北京市接单至少3次的司机的平均接单数和平均兼职收入
#输出:city、avg_order_num、avg_income
#要求:时间区间为2021-10-01 and 2021-10-07;city="北京";目标为count(order_time)>=3的司机;输出指标均保留三位小数;材料中提到取消的不算,finish_time is not null
#涉及数据:city、driver_id、order_time、fare
select "北京" city,round(avg(e1),3) avg_order_num,round(avg(e2),3) avg_income
#这里select city的原因在于,外层select没有group by;
#而没有group by并且select后面出现聚合函数的话,那么所有被select的都应该是聚合函数,否则就会报错
#既然子查询已经限制了city=北京,这里可以直接select常量规避
from(
    select city,count(order_time) e1,sum(fare) e2
    from tb_get_car_order join tb_get_car_record using(order_id)
    where date(order_time) between '2021-10-01' and '2021-10-07'
    and city="北京" and finish_time is not null
    group by driver_id
    #对司机ID进行聚合,得到每个司机的参数
    having count(order_time)>=3
) w1

全部评论

相关推荐

ResourceUt...:楼主有自己的垃圾箱,公司也有自己的人才库
点赞 评论 收藏
分享
10-22 19:44
门头沟学院 Java
面了100年面试不知...:那我得去剪个头
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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