我想可以另外新建一个年月表来关联:
年月表table:ym
一个字段:month
select to_char(t.month,'yymm') aa,sum(b) bb
from test2 t
group by to_char(t.month,'yymm')
having to_char(t.month,'yymm') ='0101'
union
select distinct ym.month aa,0 bb
from ym,test2 t
where
ym.month not in (select to_char(t.month,'yymm') from t)
应该可以的!
|