Say you have data like this:
time value
10:00 5
10:15 12
10:30 15
10:45 27
11:00 29
And a query like this:
SELECT MAX(value) - MIN(value), HOUR(time) FROM mytable GROUP BY HOUR(time);
You will get:
value time
22 10
But, I would need it to include the value at 11:00, thus the result being 24 (29-5), and not 22. Is there a way to do this in SQL or do I have no other choice than to do this manually in the code level (so, without the grouping, just fetching the data and manually subtracting).
10:00
and11:00
? Just remove thegroup by
clause.