SELECT time30, COUNT(*) AS num FROM( select DATE_FORMAT(time,'%Y-%m-%d %H:%i') as time30 from( SELECT DATE_FORMAT(concat(date(CALL_DATE), ' ',HOUR (CALL_DATE),':',floor(MINUTE(CALL_DATE)/30)*30),'%Y-%m-%d %H:%i' ) AS time FROM call_detail_records ) a ) as bGROUP BY time30;