Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - monthly average rather than daily average

I have a table called values that contains 3 columns - Location, value, date

I want to work out the average value per month

so far I have

SELECT Location, Avg(value), date  
FROM Value  
GROUP BY Location, date 

This returns the average values but a value is entered on a daily basis so I have an average per day rather than per month, how can I achieve a monthly average?

like image 475
DtotheG Avatar asked Sep 13 '12 15:09

DtotheG


1 Answers

try this:

SELECT    Location,
          Avg(value),
          month(date),
          year(date)
FROM      Value
GROUP BY  Location,
          month(date),
          year(date)
like image 61
Joe G Joseph Avatar answered Oct 26 '22 19:10

Joe G Joseph