1

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

例子

甲骨文数据库。有任何想法吗?

4

1 回答 1

2

使用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<>在这里摆弄

于 2021-09-07T11:58:39.833 回答