SELECT
a.user_id,
a.date ,
DATE_FORMAT(DATE_ADD(a.date,INTERVAL 30 MINUTE),'%Y-%m-%d %H:%i') AS date2,
u.username
FROM
(
SELECT
DATE_FORMAT(
CONCAT( DATE( created_time ), ' ', HOUR ( created_time ), ':', floor( MINUTE ( created_time )/ 30 ) * 30 ),
'%Y-%m-%d %H:%i'
) AS date ,user_id
FROM
task_numbers
GROUP BY
date
) a LEFT JOIN users u ON a.user_id = u.id;
结果展示