MySQL:在group_concat 中使用concat 时如何排序?

skh*_*ams 3 mysql sql group-concat

我需要排序dateconcat范围内group_concat,而我的查询运行良好:

 SELECT 
    report.`Name`,
    GROUP_CONCAT(
      CONCAT(
        "[",
      DATE(report.Date) --(not working) order by DATE(report.Date)  ,
        ',',
      report.ProductPrice --(not working) order by DATE(report.ProductPrice) ,
        "]"
      ) 
    ) AS ProductPrice  
  FROM report
 GROUP BY report.Name ;
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

pot*_*hin 5

您应该在 中使用它group_concat,而不是concat

group_concat(
  concat('[', date(report.Date), ',', report.ProductPrice, ']') 
  order by date(report.Date) desc
)
Run Code Online (Sandbox Code Playgroud)