I\'m having a slight issue. I have a PostgreSQL table with such format
time (datetime) | players (int) | servers (int)
----------------------------------
How about this?
select datepart('year', time) as StartYear, datepart('month', time) as StartMonth,
datepart('day', time) as StartDay, datepart('hour', time) as StartHour,
floor(datepart('minute', time)/5)*5 as StartMinute,
avg(case when datepart('minute', time) = floor(datepart('minute', time)/5)*5 then players else null end) as Zero,
avg(case when datepart('minute', time) = floor(datepart('minute', time)/5)*5+1 then players else null end) as One,
avg(case when datepart('minute', time) = floor(datepart('minute', time)/5)*5+2 then players else null end) as Two,
avg(case when datepart('minute', time) = floor(datepart('minute', time)/5)*5+3 then players else null end) as Three,
avg(case when datepart('minute', time) = floor(datepart('minute', time)/5)*5+4 then players else null end) as Four,
from MyTable
group by datepart('year', time), datepart('month', time),
datepart('day', time), datepart('hour', time),
floor(datepart('minute', time)/5)*5