I think that your approach is flawed. If you're measuring precipitation, then you want to measure from (a nano-second after) the beginning of the hour to the end of that hour (i.e. from 13:00:00.000000001 to 14:00:00.000000000) and not from a ns after 13:55 to 14:05.
Your approach essentially misses out on the 5 minutes of precipitation between 55 minutes past the hour and the hour mark!
This can be best shown by an example (the code below is available on the fiddle here):
CREATE TABLE prec -- precipitation and NOT rain! My dad was a meterologist
(
id INT NOT NULL,
rain FLOAT NOT NULL,
ts TIMESTAMP NOT NULL
);
populate it:
Now, I think that you're approaching this in the wrong way!
What you want is something more like the precipitation between, say, 13:00:00 and 13:05:00, and then between 13:05:00 and 13:10:00.
So, we assume that precipitation (just after) 13:00:00 is zero, but that a measurement at 13:00:00 represents it between 12:00:00 and 13:00:00, so I would have something more like this:
Basically, the first measurement for any period is at 5 minutes past the hour and not on the hour!
INSERT INTO prec VALUES
(0, 3.5, '2021-10-04 11:55:00'),
(1, 4.2, '2021-10-04 12:00:00'), -- last measurement - highest
--
-- starts again after the hour
--
(2 , 0.2, '2021-10-04 12:05:00'), -- first measurement for period
(3 , 0.6, '2021-10-04 12:10:00'),
(4 , 0.9, '2021-10-04 12:15:00'),
(5 , 0.9, '2021-10-04 12:20:00'),
(6 , 1.4, '2021-10-04 12:25:00'),
(12, 2.5, '2021-10-04 12:55:00'),
(13, 2.6, '2021-10-04 13:00:00'), -- last measurement for period
--
-- starts again **FROM** the hour!
--
(14, 0.1, '2021-10-04 13:05:00'), -- 05:00 - lowest
(15, 0.6, '2021-10-04 13:10:00'),
(24, 1.5, '2021-10-04 13:55:00'),
(25, 1.8, '2021-10-04 14:00:00'); -- 00:00 - highest
Queries:
Query 1 (flawed)
SELECT
rain, ts, DATE(ts), HOUR(ts), MINUTE(ts)
FROM
prec
WHERE MINUTE(ts) = 55;
Result:
rain ts DATE(ts) HOUR(ts) MINUTE(ts)
3.5 2021-10-04 11:55:00 2021-10-04 11 55
2.5 2021-10-04 12:55:00 2021-10-04 12 55
1.5 2021-10-04 13:55:00 2021-10-04 13 55
Query 2 (correct way)
SELECT
rain, ts, DATE(ts), HOUR(ts), MINUTE(ts)
FROM
prec
WHERE MINUTE(ts) = 0;
Result:
rain ts DATE(ts) HOUR(ts) MINUTE(ts)
4.2 2021-10-04 12:00:00 2021-10-04 12 0
2.6 2021-10-04 13:00:00 2021-10-04 13 0
1.8 2021-10-04 14:00:00 2021-10-04 14 0
So, the MINUTE(ts) = 55
is missing out data!
You might be better off taking a cumulative approach to precipation over, say, a year and doing subtractions. With window functions (LAG()/LEAD()), this should be easy enough!