请参阅以下查询。
SELECT date_format(`date`, '%d %b %Y') AS Datum,
AVG(NULLIF(`temp` ,0)) AS Temp,
AVG(NULLIF(`cod` ,0)) AS CZV,
AVG(NULLIF(`nh4` ,0)) AS NH4
FROM reactor1
GROUP BY `datum` DESC
这将返回正确的数据,但日期的排序顺序不正确。它按日排序日期。
01-NOV
05-NOV
07-DEC
09-DEC
13-NOV
我在这里做错了什么?
答案 0 :(得分:2)
试试这个
SELECT date_format(`date`, '%d %b %Y') AS Datum,
AVG(NULLIF(`temp` ,0)) AS Temp,
AVG(NULLIF(`cod` ,0)) AS CZV,
AVG(NULLIF(`nh4` ,0)) AS NH4
FROM reactor1
GROUP BY `Datum` ORDER BY `Datum` DESC
答案 1 :(得分:1)
试试这个:
SELECT DATE_FORMAT(r.date, '%d %b %Y') AS Datum,
AVG(NULLIF(r.temp, 0)) AS Temp,
AVG(NULLIF(r.cod, 0)) AS CZV,
AVG(IFNULL(r.nh4, 0)) AS NH4
FROM reactor1 r
GROUP BY DATE(r.date)
ORDER BY DATE(r.date) DESC;