分组

group_concat

语法: group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator ‘分隔符’])

  1. -- type 分组,age 字段合并(,分割)
  2. select group_concat(age) from tab group by type;
  3. 1 20,30,40
  4. 2 24
  5. -- type 分组,age 字段合并,指定 # 分割
  6. select group_concat(age separator '#') from tab group by type;
  7. 1 20#30#40
  8. 2 24
  9. -- type 分组,age 字段合并,按照 id 倒序,指定 # 分割
  10. select group_concat(age order by id desc separator '#') from tab group by type;
  11. 1 40#30#20
  12. 2 24