AI BI
11 KN 20
11 SU 30
23 MM 40
90 DD 50上面表有两字段AI,BI,如果给出一个数字10,想增加一列内容为在10的基础上进行累加,如上面第三列字段内容。
不知语句如何写,请高手帮忙。TKS!

解决方案 »

  1.   

    declare @var int
    set @var = 你需要的数字
    update 表名 set AI = AI + @VAR
    GO
    AI BI
    21 KN
    21 SU
    33 MM
    100 DD
    结果应该是这样~
      

  2.   

    内容是要增加一列,给出一个数字,在此基础上每行进行累加,如给10
    AI BI   增加列名
    11 KN   20
    11 SU   30
    23 MM   40
    90 DD   50
     
      

  3.   

    declare @t table 
    (AI int not null,
     BI varchar(4) not null
    )
    insert into @t
    select 11,'KN' union all
    select 11,'SU' union all
    select 23,'MM' union all
    select 90,'DD' declare @n int 
    set @n = 10;with t as (
    select row_number() over(order by AI ,BI ) as ID,*,@n as n from @t
    )select *,(select sum(n) from t b where b.id <= a.id) from t a