问题 : 每4小时统计一次数据 ;
需求分析:0~23 分成6组 分别是:
mysql 实现逻辑 :
1 select id,FLOOR(id/4) hourGroup 2 , case FLOOR(id/4) 3 when 0 then '00:00~04:00' 4 when 1 then '04:00~08:00' 5 when 2 then '08:00~12:00' 6 when 3 then '12:00~16:00' 7 when 4 then '16:00~20:00' 8 when 5 then '20:00~00:00' end hourRange 9 from ( 10 select 0 as id union 11 select 1 as id union 12 select 2 as id union 13 select 3 as id union 14 select 4 as id union 15 select 5 as id union 16 select 6 as id union 17 select 7 as id union 18 select 8 as id union 19 select 9 as id union 20 select 10 as id union 21 select 11 as id union 22 select 12 as id union 23 select 13 as id union 24 select 14 as id union 25 select 15 as id union 26 select 16 as id union 27 select 17 as id union 28 select 18 as id union 29 select 19 as id union 30 select 20 as id union 31 select 21 as id union 32 select 22 as id union 33 select 23 as id 34 ) t 35 order by id ;