tags:

views:

21

answers:

2

I have a column of datetimes, and a column of values. How do I add up all teh values that occur on the same day? so like... midnight:01 to 23:5 => add all the records that occur in that time period.

then group by day.

bit hard to explain. sadness.

+4  A: 

Use:

SELECT SUM(t.value_column)
  FROM TABLE t
GROUP BY DATE(t.datetime_column)

The DATE function only captures the year/month/day portion - time is ignored, so anything on that date will be grouped together.

OMG Ponies
+1, was about to write exactly the same
jigfox
+1  A: 

In MySQL:

SELECT  CAST(datetime_field AS DATE) AS date_field, SUM(value)
FROM    mytable
GROUP BY
        date_field
Quassnoi