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 

  

 posted on 2019-06-25 14:35  改变一下  阅读(1106)  评论(0编辑  收藏  举报