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 #

解决方案 »

  1.   

    to vivian:原来很多情况, 标量函数是可以省略的哦.
    还不知道呢.
      

  2.   

    --建立测试环境
    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
    */
      

  3.   

    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)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
    */