Oracle-with c as (select ......) 实现多次调用子查询结果

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 @ 2020-04-22 10:12  马踏飞燕Beautiful  阅读(876)  评论(0编辑  收藏  举报