题解 | 国庆期间近7日日均取消订单量
国庆期间近7日日均取消订单量
https://www.nowcoder.com/practice/2b330aa6cc994ec2a988704a078a0703
啊啊啊好长,但是这样的是一步一步想出来的,很清晰详细
select t2.date1 as dt,round(finished/7,2),round(canceled/7,2)
from
( select date1,count(distinct order_id) finished
from
( select c.order_id,date(b.finish_time) as date1,
date(c.finish_time) as date2
from tb_get_car_order b,tb_get_car_order c
where datediff(b.finish_time,c.finish_time)>=0
and datediff(b.finish_time,c.finish_time)<=6
and c.start_time is not null
order by date1,date2) t1
where day(date1)=1
or day(date1)=2
or day(date1)=3
group by date1) t2,
( select date1,count(distinct order_id) as canceled
from
( select c.order_id,date(b.finish_time) as date1,
date(c.finish_time) as date2
from tb_get_car_order b,tb_get_car_order c
where datediff(b.finish_time,c.finish_time)>=0
and datediff(b.finish_time,c.finish_time)<=6
and c.start_time is null
order by date1,date2) t1
where day(date1)=1
or day(date1)=2
or day(date1)=3
group by date1) t3
where t2.date1=t3.date1
