sql - LEFT OUTER JOIN not returning NULL values -
i have pretty simple sample query trying complete.
select month(s.report_date), coalesce(count(*),0) stat_summary s left outer join ref_months m on month(s.report_date) = m.month_id group month(s.report_date)
my results like:
my desired results like:
month | count ---------------- 1 | 0 2 | 0 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0 8 | 0 9 | 4 10 | 9 11 | 0 12 | 0
you need use months table primary one:
select m.month_id, coalesce(count(s.report_date),0) ref_months m left join stat_summary s on month(s.report_date) = m.month_id group m.month_id;
Comments
Post a Comment