题解 | 国庆期间近7日日均取消订单量

国庆期间近7日日均取消订单量

https://www.nowcoder.com/practice/2b330aa6cc994ec2a988704a078a0703

#先查出要的日期
with t1 as(
select distinct date(order_time) as dt
from tb_get_car_order
where date(order_time) between '2021-10-01' and '2021-10-03'),

#查询要的字段
t2 as(
select 
date(order_time) as dt,
count(fare) as finish_num,
count(case when fare is null then 1 else null end) as cancel_num

from tb_get_car_order
group by date(order_time))

#主查询
select t1.dt,
round(avg(finish_num),2) as finish_num_7d,
round(avg(cancel_num),2) as cancel_num_7d
from t1 
left join t2
on datediff(t1.dt,t2.dt) between 0 and 6
group by t1.dt

之前做过类似的题

全部评论

相关推荐

HaxyBT:那我提前下班总可以了吧
点赞 评论 收藏
分享
03-30 19:30
石家庄学院 Java
野蛮的柯基在游泳:都能入股了,还得是Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务