--try:select a.年月,(a.金额+b.金额)/2 平均值 from
(
select rownum no,金额,年月 from
(
select * from tb where 年月>=开始年月 and 年月<=结止年月 order by 年月
)
) a,
(
select 1 no,金额,年月 from tb where 年月=开始年月 union all
select rownum+1,金额,年月 from
(
select 金额,年月 from tb where 年月>=开始年月 and 年月<=结止年月 order by 年月
)
) b
where a.no=b.no;
(
select rownum no,金额,年月 from
(
select * from tb where 年月>=开始年月 and 年月<=结止年月 order by 年月
)
) a,
(
select 1 no,金额,年月 from tb where 年月=开始年月 union all
select rownum+1,金额,年月 from
(
select 金额,年月 from tb where 年月>=开始年月 and 年月<=结止年月 order by 年月
)
) b
where a.no=b.no;
where 年月 < '200412' --不包含本月
and 年月 >= to_char(add_months(to_date('200412','yyyymm'),-2),'yyyymm') --有上一个月和大上个月的