Author Topic: Daily Averages per Month  (Read 330 times)

0 Members and 1 Guest are viewing this topic.

Offline _spazTopic starter

  • Irregular
  • Posts: 34
    • View Profile
Daily Averages per Month
« on: April 01, 2010, 12:34:25 AM »
How does one get the daily averages per month from a bunch of data with titles and Durations on different dates?

Example:
date              Title      Duration
2010-02-01      1           10
2010-02-03      2           16
2010-02-01      3            24
2010-03-02       4           10
2010-03-08       5           10
etc...


I have this so far but its not calculating the daily average by Month properly

Select Month(`date`) as Month,
avg(`duration`) AS 'Daily Duration'
from Table
where `date` between '2009-01-01' and '2009-12-31'
group by Month

Offline JustLikeIcarus

  • Enthusiast
  • Posts: 415
  • Gender: Male
    • View Profile
Re: Daily Averages per Month
« Reply #1 on: April 01, 2010, 10:57:35 AM »
Try one of these.  I think you want the second one
For Monthly Averages
Code: [Select]
Select Month(`date`),  avg(`duration`) AS 'Daily Duration'
from Table
where `date` between '2009-01-01' and '2009-12-31'
group by Month(`date`)

For Daily averages
Code: [Select]
Select Month(`date`), Day(`date`), avg(`duration`) AS 'Daily Duration'
from Table
where `date` between '2009-01-01' and '2009-12-31'
group by Month(`date`), Day(`date`)
I was contemplating the immortal words of Socrates who said "I ate what?"