发布网友 发布时间:2022-04-24 04:40
共4个回答
热心网友 时间:2022-04-10 13:35
CREATE TABLE #tempTable(
id INT,
NO INT,
value decimal(5,3),
lastValue decimal(5,3),
);
GO
INSERT INTO #tempTable
SELECT 1, 1, 0.112, null UNION ALL
SELECT 3, 2, 0.221, null UNION ALL
SELECT 4, 3, 0.321, null UNION ALL
SELECT 5, 4, 0.142, null UNION ALL
SELECT 6, 5, 0.281, null
GO
UPDATE
#tempTable
SET
lastValue = T2.value
FROM
#tempTable JOIN #tempTable T2
ON (#tempTable.id = T2.id + 1)
GO
1>
2> SELECT * FROM #tempTable
3> GO
id NO value lastValue
----------- ----------- ------- ---------
1 1 .112 NULL
3 2 .221 NULL
4 3 .321 .221
5 4 .142 .321
6 5 .281 .142
(5 行受影响)
热心网友 时间:2022-04-10 14:53
update table t1
set lastValue = (select value from table t2 where t1.no = t2 -1)
似乎是这样,你再试试
热心网友 时间:2022-04-10 16:27
update a set a.lastvalue=b.value
from tb as a join tb as b on a.no=b.no+1
热心网友 时间:2022-04-10 18:19
Update tablename
Set lastvalue=A.value
From (Select id-1 As id, value From tablename) A
Where tablename.id=A.id
把原来的表重新抽出个view,id减1,和原来的对应起来就可以。