I have this query:
Code:
SELECT SUM(t1.totalprice) as totalprice,
SUM(t1.sales) as salessubtotal, t1.`year` as `year`,
t1.mnth as `month`
from
(SELECT
Sum(crm_sales.totalprice) AS totalprice,
MONTHNAME(crm_sales.date) AS mnth,
YEAR(crm_sales.date) AS `year`,
Count(crm_sales.totalprice) AS sales,
MONTH(crm_sales.date) AS `ordering`
FROM `crm_sales`
WHERE `date` BETWEEN '2009-01-01' AND '2010-05-28'
GROUP BY crm_sales.date
) as t1
GROUP BY t1.`year`,t1.mnth
ORDER BY t1.`year`, t1.ordering
TotalPrice Sales Year Month
130567.41 635 2009 May
139533.66 682 2009 June
141245.63 681 2009 July
121226.32 588 2009 August
121582.47 588 2009 September
134636.40 660 2009 October
107815.05 524 2009 November
106716.81 521 2009 December
123851.60 609 2010 January
126752.72 619 2010 February
151362.32 732 2010 March
124616.72 605 2010 April
150702.71 736 2010 May
The query returns the correct data but i need the missing months to be 0 for sales.
ANy ideas