我有一个表db2admin.shdl_dtl,其中有两列日期 -
STARTDATE 结束日期
从这两个日期列中我想显示两个日期之间的月份
即。 startdate =' 2015-01-05'并结束=' 2015-04-20'那么查询的输出应该是这样的 -
输出 - jan,feb,mar,apr
答案 0 :(得分:1)
with cte (diffmonths,monthdiff) as
(select date(startdate ) as diffmonths,0 from sysibm.sysdummy1
union all
select date(diffmonths) + 1 month as diffmonths,month(diffmonths) from cte
where diffmonths<=(date(enddate)) )
select * from cte where MONTHDIFF >0