Reputation: 25
My MySQL table looks like this:
date value
2014-08-13 08:00 12
2014-08-13 09:00 38
2014-08-13 10:00 64
2014-08-14 08:00 7
2014-08-14 09:00 19
2014-08-14 10:00 41
I want to get the sum of month 8, only adding the highest value. E.g. here 105 (64 + 41)
Can I get this with only one MySQL query?
Upvotes: 1
Views: 114
Reputation: 204844
select sum(t1.value)
from your_table t1
join
(
select max(datetime_column) as mdate
from your_table
group by date(datetime_column)
) t2 on t1.datetime_column = t2.mdate
Upvotes: 1