-- 将学生按班级分组,对同一班级的学生姓名进行拼接
SELECT classid,group_concat(stu_name) as stu_names FROM student GROUP BY classid
2、不同表将某几个字段的值进行拼接
-- 将客户的负责人表crm_share_join中负责人beshare_uid以cid分组,查询同一客户多个负责人, 查询 new_charege 字段以 (创建人uid,负责人A,负责人B,负责人C...,) 形式展示
SELECT
s.cid,
s.beshare_uid,
s.share_uid,
c.creatid,
c.id,
c.charge_person,
CONCAT(c.creatid,',',group_concat(s.beshare_uid),',') as new_charege
FROM
crm_share_join s,
crm_customer c
WHERE
s.cid = c.id
AND s.creat_id <> s.beshare_uid
GROUP BY
s.cid
HAVING
new_charege<> c.charge_person