关于数字累加的问题,请高手帮忙!
AIBI
11KN20
11SU30
23MM40
90DD50
上面表有两字段AI,BI,如果给出一个数字10,想增加一列内容为在10的基础上进行累加,如上面第三列字段内容。
不知语句如何写,请高手帮忙。TKS!
[解决办法]
declare @var int
set @var = 你需要的数字
update 表名 set AI = AI + @VAR
GO
AI BI
21 KN
21 SU
33 MM
100 DD
结果应该是这样~
[解决办法]
- SQL code
declare @t table (AI int not null, BI varchar(4) not null)insert into @tselect 11,'KN' union allselect 11,'SU' union allselect 23,'MM' union allselect 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