0

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.

jigfox
  • 18,057
  • 3
  • 60
  • 73
NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352

2 Answers2

4

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
  • 325,700
  • 82
  • 523
  • 502
1

In MySQL:

SELECT  CAST(datetime_field AS DATE) AS date_field, SUM(value)
FROM    mytable
GROUP BY
        date_field
Quassnoi
  • 413,100
  • 91
  • 616
  • 614