select nvl(count(*),0) smscount ,to_char(sendtime,'yyyy-mm') month,nvl(sum(fee),0) feesum
from
(select '2005-01' Date1 from tmp union
select '2005-02' as Date1 from tmp union
select '2005-03' as Date1 from tmp union
select '2005-04' as Date1 from tmp union
select '2005-06' as Date1 from tmp union
select '2005-07' as Date1 from tmp union
select '2005-08' as Date1 from tmp union
select '2005-09' as Date1 from tmp union
select '2005-10' as Date1 from tmp union
select '2005-11' as Date1 from tmp union
select '2005-12' as Date1 from tmp ) a left join
m_sendhistory b
on
a.Date1(+)=TO_CHAR(b.sendtime,'YYYY-MM')
where deptid = 244
and to_char(sendtime,'yyyy')='2006'
group by to_char(sendtime,'yyyy-mm')
order by to_char(sendtime,'yyyy-mm')