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
生活其实也很简单,喜欢的就去争取、得到的就珍惜、失去的就忘记。