[英]Split months into 4 and retrieve the average value per day
您有一个每天分组的查询,例如:
select
the_date as day,
sec_to_time(avg(timestampdiff(second, start_time, end_time))) as duration
from ...
group by the_date;
您需要每月1-7、8-14、15-21、22天结束。 使用CASE WHEN
构建组。
select
year(the_date) as year,
month(the_date) as month,
case
when day(the_date) <= 7 then '01-07'
when day(the_date) <= 14 then '08-14'
when day(the_date) <= 21 then '15-21'
else '22-end'
end as day_range,
sec_to_time(avg(timestampdiff(second, start_time, end_time))) as duration
from ...
group by year, month, day_range
order by year, month, day_range;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.