oracle統計每月資料量 沒有月份返回0
阿新 • • 發佈:2019-02-06
補充1到12月表
with temps as (select lpad(level, 2, 0) as mon from dual connect by level < 13) select decode(t.mon, '01', '一月', '02', '二月', '03', '三月', '04', '四月', '05', '五月', '06', '六月', '07', '七月', '08', '八月', '09', '九月', '10', '十月', '11', '十一月', '12', '十二月') as mon, count(to_char(t1.item_time, 'yyyy-mm')) as num from temps t left join site_c_menu_info t1 on t.mon = to_char(t1.item_time, 'mm') and to_char(t1.item_time(+), 'yyyy') = #{year,jdbcType=VARCHAR} group by t.mon order by t.mon