with c as (select a.trandt,sum(a.tranam) tranam from tran a group by a.trandt ) #将子查询抽取出来,以后可以直接重复使用。该方法只适用于oracle,mysql不支持
select c.trandt, sum(d.tranam)
from c
inner join c d
on c.trandt >= d.trandt
group by c.trandt
select c.trandt, sum(d.tranam)
from (select a.trandt, sum(a.tranam) tranam
from tran a
group by a.trandt
order by a.trandt) c
inner join (select a.trandt, sum(a.tranam) tranam
from tran a
group by a.trandt
order by a.trandt) d
on c.trandt >= d.trandt
group by c.trandt