select year(date) as y,month(date) as m,day(date) as d,type
,sum(case when MINUTE(NOW()) between 0 and 5 then user end) as sm1
,sum(case when MINUTE(NOW()) between 6 and 10 then user end) as sm2
,sum(case when MINUTE(NOW()) between 11 and 15 then user end) as sm3
,sum(case when MINUTE(NOW()) between 16 and 20 then user end) as sm4
,sum(case when MINUTE(NOW()) between 21 and 25 then user end) as sm5
,sum(case when MINUTE(NOW()) between 26 and 30 then user end) as sm6
,sum(case when MINUTE(NOW()) between 31 and 35 then user end) as sm7
,sum(case when MINUTE(NOW()) between 36 and 40 then user end) as sm8
,sum(case when MINUTE(NOW()) between 41 and 45 then user end) as sm9
,sum(case when MINUTE(NOW()) between 46 and 50 then user end) as sm10
,sum(case when MINUTE(NOW()) between 51 and 55 then user end) as sm11
,sum(case when MINUTE(NOW()) between 56 and 59 then user end) as sm12
from tablename
group by year(date),month(date),day(date),type
order by year(date),month(date),day(date),type asc