Page 1 of 1

Solved: Get average by month on a select.

Posted: Wed Jan 27, 2016 9:34 pm
by mister_v
Hi,

I have a table with date for every day.
But I want the average by month.

Is there a simple query that can do that,
Or do I have to calculate it on the application layer?

Re: Get average by month on a select.

Posted: Wed Jan 27, 2016 9:36 pm
by chris
You can do it in one query:

Code: Select all

SELECT id,year(date),month(date),avg(price) FROM table GROUP BY id,year(date),month(date)
I haven't compared the speed,
but it is probably faster then to do it in the application.