SQL 第一行结果相反
SQL First row result in reverse
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
上面的代码 returns 除了第一行之外的所有行都正确。 chartData
中第一组数据倒过来
In the first row, the 20 should be after the 58
提前致谢!
我假设您 table 中有一个名为 date
的列。要按它排序,请使用 ORDER BY date
而不是 ORDER BY 'date'
,即不要将列名括在单引号中。 'date'
只是一个字符串文字,按它排序就像根本不排序一样,因为它对所有行都是相等的。
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
上面的代码 returns 除了第一行之外的所有行都正确。 chartData
中第一组数据倒过来
In the first row, the 20 should be after the 58
提前致谢!
我假设您 table 中有一个名为 date
的列。要按它排序,请使用 ORDER BY date
而不是 ORDER BY 'date'
,即不要将列名括在单引号中。 'date'
只是一个字符串文字,按它排序就像根本不排序一样,因为它对所有行都是相等的。