GROUP_CONCAT multiple fields with a different separator

梦想的初衷 提交于 2019-12-08 16:58:41

问题


Is it possible to do something like:

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

The result is John3.99, Mike24.99

What I need is something like:

John - 3.99, Mike - 24.99

Basically use another type of separator for price field.


回答1:


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

Or just

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



回答2:


Try this way

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


来源:https://stackoverflow.com/questions/38816859/group-concat-multiple-fields-with-a-different-separator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!