【问题标题】:GROUP_CONCAT multiple fields with a different separatorGROUP_CONCAT 具有不同分隔符的多个字段
【发布时间】:2016-12-13 11:59:49
【问题描述】:

是否可以这样做:

GROUP_CONCAT(user, price SEPARATOR ', ') AS items

结果是John3.99, Mike24.99

我需要的是这样的:

John - 3.99, Mike - 24.99

价格字段基本上使用另一种类型的分隔符。

【问题讨论】:

    标签: mysql group-concat


    【解决方案1】:
    GROUP_CONCAT(CONCAT(user, ' - ', price) SEPARATOR ', ') AS items
    

    或者只是

    GROUP_CONCAT(user, ' - ', price SEPARATOR ', ') AS items
    

    【讨论】:

      【解决方案2】:

      试试这个方法

      GROUP_CONCAT(
        DISTINCT CONCAT(user,',',Price SEPERATOR) 
        ORDER BY items 
        SEPARATOR ';'
      )
      

      【讨论】:

        猜你喜欢
        • 2016-12-12
        • 2015-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-14
        相关资源
        最近更新 更多