题解 | #国庆期间近7日日均取消订单量#不用窗口函数

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

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

select dt,round(finish_num/7,2) finish_num_7d,
round(cancel_num/7,2) cancel_num_7d
from
(select distinct date(order_time) dt,
(select sum(if(start_time is null,0,1)) 
from tb_get_car_order
where timestampdiff(day,date(order_time),dt) between 0 and 6
)  finish_num,
(select sum(if(start_time is null,1,0)) 
from tb_get_car_order
where timestampdiff(day,date(order_time),dt) between 0 and 6
)  cancel_num
from 
tb_get_car_order t1
where 
date(order_time) between '2021-10-01' and '2021-10-03')t2

策略是筛选出10.1-10.3之间并去重的dt

基于这个基础在执行两个select字句

查询与当前dt间隔0-6天的数据并汇总

全部评论

相关推荐

09-13 08:41
服装/纺织设计
那一天的Java_J...:你第一次参加面试吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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