SELECT
ANY_VALUE(id) AS 'id',
office_id,
IF(
POSITION(',' IN GROUP_CONCAT(employee_id))=0,
GROUP_CONCAT(employee_id),
SUBSTR(GROUP_CONCAT(employee_id), 1, POSITION(',' IN GROUP_CONCAT(employee_id))-1)
) AS 'employee_id_first',
IF(
POSITION(',' IN GROUP_CONCAT(employee_id))=0,
NULL,
SUBSTR(
RIGHT(GROUP_CONCAT(employee_id), LENGTH(GROUP_CONCAT(employee_id))-POSITION(',' IN GROUP_CONCAT(employee_id))),
1,
POSITION(',' IN RIGHT(GROUP_CONCAT(employee_id), LENGTH(GROUP_CONCAT(employee_id))-POSITION(',' IN GROUP_CONCAT(employee_id))))-1
)
) AS 'employee_id_second'
FROM
t
GROUP BY
office_id