我正在尝试在表格中添加一列重复的线性数字,并停留在287并重复。代码的工作原理是表更新,但所有行都是零而不是我想要的数字。 With子句有效,因为我可以看到它在使用select时有效,因为更新了。
WITH myupdate (myrownumber)
AS (SELECT ( Row_number()
OVER (
partition BY tmc, date
ORDER BY tmc, date, epoch) - 1 ) AS myRowNumber
FROM [dbo].[i40_2016_all])
--SELECT * FROM myUpdate
UPDATE [dbo].[i40_2016_all]
SET mod_epoch = myrownumber
FROM myupdate
答案 0 :(得分:0)
我猜你正在使用SQL Server。我认为你想要的语法是这样的:
WITH myUpdate AS (
SELECT a.*,
ROW_NUMBER() over (PARTITION BY TMC, DATE ORDER BY TMC, DATE, EPOCH) - 1 AS myRowNumber
FROM [dbo].[I40_2016_ALL] a
)
UPDATE myUpdate
SET MOD_EPOCH = myRowNumber;