create table #
(
num int
)insert #
select 1 union select 2 union select 3 union select 4 union select 5select (select isnull(sum(num),1) from # where num<=A.num) from # Adrop table #
(
num int
)insert #
select 1 union select 2 union select 3 union select 4 union select 5select (select isnull(sum(num),1) from # where num<=A.num) from # Adrop table #
还不知道呢.
Create Table A(ID Int)
Insert A Select 1
Union Select 2
Union Select 3
Union Select 4
Union Select 5
--测试
Select ID=(Select SUM(ID) from A Where ID<=T.ID) from A T
--删除测试环境
Drop Table A
--结果
/*
ID
1
3
6
10
15
*/
(
num int
)insert #
select 1 union select 2 union select 3 union select 4 union select 5select (select isnull(sum(num),1) from # where num<=A.num)col1,
cast(isnull((select sum(num) from # where num<A.num),0) as varchar)+'+'+
cast(num as varchar) [operation]
from # Adrop table #--结果
/*col1 operation
----------- --------------
1 0+1
3 1+2
6 3+3
10 6+4
15 10+5
*/