更新重复数据

时间:2013-12-09 09:12:43

标签: sql sql-server

我有一个Calisma数据库,它有DosyaNo和SiraNo列。 我想设置SiraNo,例如DosyaNo是相同的

DosyaNo ____________SiraNo
0.00000000__________1
0.00000000__________2
0.00000000__________3
0.00000000__________4
0.00000000__________5
---------------------
0.10000000__________1
0.10000000__________2
0.10000000__________3
0.10000000__________4
0.10000000__________5
-----------------------
0.70000000__________1
0.70000000__________2
0.70000000__________3
------------------------
7.10000000__________1
7.10000000__________2

1 个答案:

答案 0 :(得分:1)

你可以使用CTE

WITH cte AS 
(
  SELECT DosyaNo, SiraNo, 
         ROW_NUMBER() OVER (PARTITION BY DosyaNo ORDER BY (SELECT NULL)) rnum
  FROM table1
)
UPDATE cte
   SET SiraNo = rnum

这是 SQLFiddle 演示