记录:mysql行合并列合并显示

搬砖时遇到一个sql需要合并行 且 合并 列字段 显示的要求,好像是第一次写,记录一下。

SELECT
  b.push_id AS pushId,
    b.push_time AS pushTime,
    c.real_name AS recivePerson,
    a.school_name AS school,
    a.real_name AS studentName,
    a.eng_name AS studentEngName,
    a.class_name AS classess,
    a.area AS passArea,
    a.pass_type AS passResult,
    a.pass_url AS passPicture,
    a.pass_time AS passTime,
 GROUP_CONCAT( CONCAT(a.real_name,'(',c.push_state,')') )
FROM
    pass_record a,
    push_record b,
    push_record_msg c
WHERE
    a.record_id = b.record_id
AND b.push_id = c.push_id
GROUP BY 

pushId

 

其中,CONCAT(clounm a,clounm b,...) 表示合并列字段显示(拼接字符);

            GROUP_CONCAT 要和GROUP BY 联合使用才有效

 

你可能感兴趣的:(数据库)