重复的行编号

Duplicated rows numbering

我需要对行进行编号,使具有相同ID的行号相同。例如:

甲骨文数据库。有什么想法吗?

使用DENSE_RANK解析函数:

SELECT DENSE_RANK() OVER (ORDER BY id) AS row_number,
       id
FROM   your_table

其中,对于示例数据:

CREATE TABLE your_table ( id ) AS
SELECT 86325 FROM DUAL UNION ALL
SELECT 86325 FROM DUAL UNION ALL
SELECT 86326 FROM DUAL UNION ALL
SELECT 86326 FROM DUAL UNION ALL
SELECT 86352 FROM DUAL UNION ALL
SELECT 86353 FROM DUAL UNION ALL
SELECT 86354 FROM DUAL UNION ALL
SELECT 86354 FROM DUAL;

输出:

ROW_NUMBER ID
1 86325
1 86325
2 86326
2 86326
3 86352
4 86353
5 86354
5 86354

db<>fiddle here