Hi,
I'm trying to write a MySQL query to get an average value per month, for all months between to given dates. My idea is this:
Query, something like
SELECT AVG(value1) as avg_value_1,
AVG(value2) as avg_value_2,
MONTH(save_date) as month,
YEAR(save_date) as year
FROM myTable
WHERE save_date BETWEEN '2009-01-01' AND '2009-07-01'
GROUP BY YEAR(save_date), MONTH(save_date)
avg_value_1 | avg_value_2 | month | year
5 | 4 | 1 | 2009
2 | 1 | 2 | 2009
7 | 5 | 3 | 2009
0 | 0 | 4 | 2009 <---
6 | 5 | 5 | 2009
3 | 6 | 6 | 2009
You see, no values were entered during April 2009, yet i want it to show up as a 0, 0 value in output. Any ideas on how to achieve this? Can it be done within MySQL?