How to use GROUP_CONCAT in a CONCAT in MySQL

前端 未结 7 1864
旧巷少年郎
旧巷少年郎 2020-11-22 11:38

If I have a table with the following data in MySQL:

id       Name       Value
1          A          4
1          A          5
1          B          8
2               


        
相关标签:
7条回答
  • 2020-11-22 11:58
     SELECT id, GROUP_CONCAT(CONCAT_WS(':', Name, CAST(Value AS CHAR(7))) SEPARATOR ',') AS result 
        FROM test GROUP BY id
    

    you must use cast or convert, otherwise will be return BLOB

    result is

    id         Column
    1          A:4,A:5,B:8
    2          C:9
    

    you have to handle result once again by program such as python or java

    0 讨论(0)
提交回复
热议问题