有一种情况下,我们可以将一个条件查询出的一条或多条记录拼接成一个字符串作为一个字段显示:
SELECT
GROUP_CONCAT(ag.group_name) AS authorityGroupName,
tg.teacher_id AS teacherId
FROM
authority_teacher_group tg
LEFT JOIN authority_group ag ON tg.group_id = ag.id
WHERE 1=1
and ag.group_type in (3,5)
AND ag.organization_id = 3
AND tg.is_deleted = 0
AND ag.is_deleted = 0
GROUP BY
tg.teacher_id
结果显示如下: