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
  • 17,756
  • 3
  • 56
  • 73
NullVoxPopuli
  • 56,640
  • 72
  • 202
  • 343

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
  • 314,254
  • 77
  • 507
  • 490
1

In MySQL:

SELECT  CAST(datetime_field AS DATE) AS date_field, SUM(value)
FROM    mytable
GROUP BY
        date_field
Quassnoi
  • 398,504
  • 89
  • 603
  • 604