多部门拼接查询
SELECT
a.*,
GROUP_CONCAT( r.role_name ) roleNames
FROM
(
SELECT
ru.role_id,
ru.user_id,
u.username,
u.real_name,
d.dept_name,
u.user_type,
u.job_title,
group_concat( ru.role_id ) roleIds
FROM
t_role_user ru
LEFT JOIN t_user u ON u.id = ru.user_id
LEFT JOIN t_dept d ON d.id = u.dept_id
WHERE
ru.del_flag = 0
AND u.del_flag = 0
GROUP BY
ru.user_id
) a
LEFT JOIN t_role r ON FIND_IN_SET( r.id, a.roleIds )
WHERE
1 = 1
GROUP BY
a.user_id