I have a temperature table with postcode, temperature and date. How do I get the day with the lowest temperature for a postcode within a dedicated date-period?
table temperatures:
postcode | temperature | date
-----------------------------------
12345 | 35.7 | 2022-02-01
12345 | 32.8 | 2022-02-02
12345 | 31.3 | 2022-02-03
34567 | 35.2 | 2022-02-01
34567 | 36.9 | 2022-02-02
Min-Temperature output for the date period 2022-02-01 to 2022-02-02 should be:
12345 | 32.8 | 2022-02-02
34567 | 35.2 | 2022-02-01
SELECT postcode, MIN(temperature), `date` FROM temperatures
WHERE `date` >= '2022-02-01' and `date` <= '2022-02-02'
GROUP BY postcode
doesn´t work.
The only idea I had was to use a cursor, but this isn´t the right approach, isn´t it?