sql从n月到m月数据汇总,没有数据,当月显示0

做个备份

-- 按月份统计
select date1, MONTHS, createtime, nvl(count2, 0)+count1 from
(
SELECT TO_CHAR(ADD_MONTHS(DATE'2018-03-01', ROWNUM-1), 'YYYY-MM') MONTHS, 0 as count1
FROM DUAL
CONNECT BY ROWNUM <= MONTHS_BETWEEN(DATE'2020-03-01', DATE'2018-03-01') + 1
)t1
left join
(
select TO_CHAR(ints.f_createtime,'YYYY-MM') date1,max(ints.f_createtime) createtime,count(*) count2 from w_sys_index_form_ints ints
GROUP BY TO_CHAR(ints.f_createtime,'YYYY-MM')
)t2 on t1.MONTHS=t2.date1
order by t1.months

posted on 2019-06-28 09:45  PPBoy  阅读(340)  评论(0编辑  收藏  举报

导航