I have a simple table:
id | temperature | timestamp |
---|---|---|
17 | 23 | 1630770051 |
18 | 24 | 1630772051 |
4799 | 35 | 1632140689 |
I want max(temperature) from today or yesterday
Example 1)
SELECT max(temperature), DAY(FROM_UNIXTIME(timestamp))
FROM `zimmer_raumdaten`
group by DAY(FROM_UNIXTIME(timestamp));
max(temperatur) DAY(FROM_UNIXTIME(timestamp))
26.70 4
26.60 5
23.90 6
44.10 7
28.00 8
35.30 9
37.80 10
31.60 11
36.70 12
36.60 13
38.30 14
26.90 15
27.10 16
46.00 17
47.90 18
23.00 19
25.00 20
Result looks good.
But when I`m trying to fetch only one result for example for today - the result mixes up the rows.
SELECT max(temperature), DAY(FROM_UNIXTIME(timestamp)), id
FROM `zimmer_raumdaten`
where DAY(FROM_UNIXTIME(timestamp)) = DAY(NOW());
max(temperatur) | DAY(FROM_UNIXTIME(timestamp)) | id |
---|---|---|
25.00 | 20 | 4977 |
The id is not correct - the row 4977 has temperature 19.00.
I appreciate every kind of ideas/thoughts on the SQL Statement.
cheers