简体   繁体   English

根据记录号更新列

[英]Update a column based on record numbers

I'm creating a column called "Deciles". 我正在创建一个名为“ Deciles”的列。 I need each decile to populate based on the range of the row numbers. 我需要根据行号的范围来填充每个十分位。 So 'Decile 1' would be between rows 1 and 364000. The syntax I've used latest has not worked. 因此,“十分位数1”将位于第1行和第364000行之间。我最近使用的语法无效。 Please keep in mind I am not a programmer. 请记住,我不是程序员。 (SQL Server 2008 is the environment I'm using). (我正在使用SQL Server 2008环境)。 HELP!! 救命!!

update dbo.August_Deciles
set Deciles = 'Decile 1'
Row_Number() over (Order By Row_Number())
between Row_Number(1) and  Row_Number(326424) 

You could try this CTE: 您可以尝试以下CTE:

WITH CTE AS
(
    SELECT Deciles,
           RN = ROW_NUMBER() OVER (ORDER BY Deciles ASC)
    FROM dbo.August_Deciles
)
UPDATE CTE SET Deciles = 'Decile ' + CAST(RN as int)

You should replace ORDER BY Deciles ASC with a meaningful order. 您应该使用有意义的顺序替换ORDER BY Deciles ASC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM