如何把SQL表中的第一行数据更新到第二行中
首先我做了个减法就是A-B=C如图中我想把第一行中的7放到第二行A中去然后第二行做减法A-B=C然后再送到第三行去,一次类推求SQL代码准确的...
首先我做了个减法 就是A-B=C
如图中 我想把第一行中的7 放到第二行A中去 然后第二行做减法A-B=C 然后再送到第三行去 ,一次类推 求SQL 代码 准确的 展开
如图中 我想把第一行中的7 放到第二行A中去 然后第二行做减法A-B=C 然后再送到第三行去 ,一次类推 求SQL 代码 准确的 展开
5个回答
展开全部
Create Table #TMP
(
ID 仔巧int identity(1,1),
firstBalance int,
lastBalance int
)
Insert Into #TMP (lastBalance) Values(1)
Insert Into #TMP (lastBalance) Values(3)
Insert Into #TMP (lastBalance) Values(5)
Insert Into #TMP (lastBalance) Values(2)
Insert Into #TMP (lastBalance) Values(9)
Insert Into #TMP (lastBalance) Values(10)
Select (Select lastBalance From #Tmp C Where ID=(Select Max(ID) From 誉戚扰#Tmp A Where 庆旦A.ID<#TMP.ID)) As firstBalance ,lastBalance From #TMP
Drop Table #TMP
--表需要一个自增的ID,如果没有,给个排序的字段也可!
展开全部
select a,b,c,lag(c) over(order by a) as AA from t_a;
这样滑升,AA就是你要的信戚老值了,然仔团后做一个更新语句。
这样滑升,AA就是你要的信戚老值了,然仔团后做一个更新语句。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
-- M$SQL:
update a set a=b.C, C=b.C-a.B
from T_A as a
JOIN T_A as b on a.Id + 1 = b.Id
update a set a=b.C, C=b.C-a.B
from T_A as a
JOIN T_A as b on a.Id + 1 = b.Id
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
create table #temp1
(
[id] [int] IDENTITY(1,1) NOT NULL,
[a] [int] NULL,
[b] [int] NULL,
[c] [int] NULL
)
insert into #temp1 (a,b,c) values(10,3,7)
declare @i int
set @i = 1
while @i < 30
begin
insert into #temp1 (a,b,c)
select c,b,c-b from #temp1 where id = @i
set @i = @i+1
end
select * from #temp1
(
[id] [int] IDENTITY(1,1) NOT NULL,
[a] [int] NULL,
[b] [int] NULL,
[c] [int] NULL
)
insert into #temp1 (a,b,c) values(10,3,7)
declare @i int
set @i = 1
while @i < 30
begin
insert into #temp1 (a,b,c)
select c,b,c-b from #temp1 where id = @i
set @i = @i+1
end
select * from #temp1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以唯枣这敏扰样
update T_A
set A = (select A from T_A where id = 1) - isnull((select sum(B) from T_A b where b.id <桥山旦 T_A.id),0),
c = (select A from T_A where id = 1) - (select sum(B) from T_A b where b.id <= T_A.id)
update T_A
set A = (select A from T_A where id = 1) - isnull((select sum(B) from T_A b where b.id <桥山旦 T_A.id),0),
c = (select A from T_A where id = 1) - (select sum(B) from T_A b where b.id <= T_A.id)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询