我有问题要填写缺少的月份和相应的0
SELECT TO_CHAR( tab.date, 'yyyy' ) "YEAR",
TO_NUMBER( TO_CHAR( tab.date, 'mm' ) ) "MONTH",
SUM(CASE tab45.id WHEN '421' THEN 1 ELSE 0 END) "421"
FROM tab,
tab45,
tab455
WHERE ( tab.date IS NOT NULL ) AND
( tab.fk_id = tab45.pk_id ) AND
( tab.fk2_id = tab455.pk_id )
GROUP BY ( TO_CHAR( tab.date, 'yyyy' ) ,
TO_NUMBER( TO_CHAR( tab.date, 'mm' ) ) )
ORDER BY 1 asc ,2 asc
返回......
year month 421
---- ---------- ----------
2014 4 3
2014 5 5
我怎么样......
year month 421
---- ---------- ----------
2014 1 0
2014 2 0
2014 3 0
2014 4 3
2014 5 5
etc.