--不知道是不是要这样的效果: with a1 (rainfail) as ( select 24 union all select 21 union all select 40 union all select 28 union all select 21 union all select 22 union all select 76 union all select 63 union all select 21 union all select 27 union all select 23 union all select 23 union all select 26 union all select 47 ) ,a2 as ( select *,'a' sort from a1 ) ,a3 as ( select *,row_number() over(order by sort) re from a2 ) select rainfail,(select sum(rainfail) from a3 a where re<=a3.re) lj from a3
如果第一条的话是默认是自己,第二条的话就是第一条跟自己相加, 一条=一条 二条=一条+二条 三条=一条+二条+三条?这样子吗?如果是这样的话,简单 select id,(select sum(rainfail) from tb b where b.id<=a.id) from tb a
(select row_number() over (order by (select 1)) as id,* from tablename
)
select sum(RainFall) from maco where id<=3
with a1 (rainfail) as
(
select 24 union all
select 21 union all
select 40 union all
select 28 union all
select 21 union all
select 22 union all
select 76 union all
select 63 union all
select 21 union all
select 27 union all
select 23 union all
select 23 union all
select 26 union all
select 47
)
,a2 as
(
select *,'a' sort from a1
)
,a3 as
(
select *,row_number() over(order by sort) re from a2
)
select rainfail,(select sum(rainfail) from a3 a where re<=a3.re) lj
from a3
一条=一条
二条=一条+二条
三条=一条+二条+三条?这样子吗?如果是这样的话,简单
select id,(select sum(rainfail) from tb b where b.id<=a.id) from tb a