简体   繁体   中英

How to use Group_Concat() to concat in MySql

I have table structure like this-

 Code         Codelang          Name

  14           de              David
  14           en              Michel
  14           es              John

I want to show this table as-

 Code                Name

 14               [:de]David[:en]Michel[:es]John[:]

Is it possible to do this using Group_Concat() or is there any other way to do this.?

SELECT
  code,
  GROUP_CONCAT(CONCAT('[:',codelang,']',name) SEPARATOR '') as name
FROM table1
GROUP BY code

to get [:] at the end you can try:

SELECT
  code,
  CONCAT(GROUP_CONCAT(CONCAT('[:',codelang,']',name) SEPARATOR ''),'[:]') as name
FROM table1
GROUP BY code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM