SQL第一行结果相反

时间:2018-10-08 16:54:34

标签: mysql sql group-concat

SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)...

上面的代码正确返回除第一行以外的所有行。 SELECT item_description, item_variant, branch, GROUP_CONCAT(sum ORDER BY 'date') AS chartData FROM ( SELECT item_description, item_variant, branch, SUM(sales) AS sum FROM inventory_branches WHERE (item_description = 'agapanthus') AND (date BETWEEN '2018-06' AND '2018-08') GROUP BY item_description, item_variant, branch, MONTH(date) DESC ) T GROUP BY item_description, item_variant, branch, MONTH('date') LIMIT 5 中的第一组数据相反

In the first row, the 20 should be after the 58

提前谢谢!

1 个答案:

答案 0 :(得分:2)

我假设您的表中有一列名为date的列。要对其进行排序,请使用ORDER BY date而不是ORDER BY 'date',即,不要将列名称括在单引号中。 'date'只是一个字符串文字,按其排序就像根本不排序一样,因为所有行都相等。