0

我有这样的桌子

file_nbr    name_seq    Person_name

10  1   James Linson

10  1   Ronn Dave

10  1   Michael Meyer

12  1   Pamela  J. Mayberry  

12  1   Randall M. Bachtel 

12  1   Cleary E. Mahaffey 

12  1   D. Scott Rowley

12  1   Stephen  L. Phelps 

12  1   Mark A. Bennet

12  1   Richard  P. Lewis 

我想更改name_seq,所以结果如下:

10  1   James Linson

10  2   Ronn Dave

10  3   Michael Meyer

12  1   Pamela  J. Mayberry  

12  2   Randall M. Bachtel 

12  3   Cleary E. Mahaffey 

12  4   D. Scott Rowley

12  5   Stephen  L. Phelps 

12  6   Mark A. Bennet

12  7   Richard  P. Lewis 

什么是最好的 SQL 查询?

4

1 回答 1

4
WITH records
AS
(
    SELECT  "file_nbr",
            ROW_NUMBER() OVER(PARTITION BY "file_nbr" ORDER BY "file_nbr") "name_seq",
            "Person_name"
    FROM    TableName
)
SELECT  "file_nbr", "name_seq", "Person_name"
FROM    records
于 2013-04-19T03:17:40.153 回答