SELECT concat( date_format(datetime,'%Y-%m-%d %k:')
, lpad(floor(minute(datetime)/5)*5,2,'0')
, ':00'
) datetime
, location
, count(1)
FROM packet_locations
GROUP BY date(datetime)
, hour(datetime)
, floor(minute(datetime)/5)
, location