1
I have two queries that are supposed to give the same result, however it is not happening.
Can someone explain to me why it is not displayed even result?
Query that returns me the expected result:
SELECT id,
ROUND(AVG(SinalGPS), 4)
FROM `012017`.gateway
WHERE ID = 8258867
AND DHEquipamento > '2017-01-22 00:00:00'
AND DHEquipamento < '2017-01-22 23:59:59'
AND ignicao = 1
ORDER BY DHEquipamento DESC;
Query that returns me the unexpected value:
SELECT id,
ROUND(AVG(CASE
WHEN DAY(gw.DHEquipamento) = 22
AND gw.Ignicao = 1 THEN sinalGPS
ELSE 0<br>
END), 4) AS '22'
FROM `012017`.gateway gw
WHERE ID = 8258867;
Obs: I need to do the second way, because I need to return IN COLUMNS the average values per day.
The difference in Querys is not in the clause
Where
? I say to be bringing difference of lines!– Marconi
@Marconi, the difference in codes is that the conditions of the Where clause in the first case, are made within the CASE in the second case. At least they should be.
– SnowBG