MySQL GROUP_CONCAT

GROUP_CONCAT

用来合并字段使用

SELECT store_id FROM istore

MySQL GROUP_CONCAT

  • 原始数据是这样的
  • 需求想合并多行数据为一行数据

SELECT GROUP_CONCAT(store_id ) from (SELECT store_id FROM store GROUP BY store_id ) a

MySQL GROUP_CONCAT

注意事项:

  • GROUP_CONCAT后面必须紧连着字段,不能有空格
  • group by 字段必须和 group_concat 字段必须一致