Используйте аналитическую функцию DENSE_RANK
:
Установка Oracle :
CREATE TABLE test_data ( id, "desc" ) AS
SELECT 152, 'abcdedasd' FROM DUAL UNION ALL
SELECT 152, 'dasdawidh' FROM DUAL UNION ALL
SELECT 152, 'das ads a' FROM DUAL UNION ALL
SELECT 194, 'dasdas da' FROM DUAL UNION ALL
SELECT 168, 'aopwejapw' FROM DUAL UNION ALL
SELECT 168, 'dasidjasd' FROM DUAL;
Запрос :
SELECT DENSE_RANK() OVER ( ORDER BY id ) AS num,
t.*
FROM test_data t
Выход :
NUM | ID | desc
--: | --: | :--------
1 | 152 | abcdedasd
1 | 152 | dasdawidh
1 | 152 | das ads a
2 | 168 | aopwejapw
2 | 168 | dasidjasd
3 | 194 | dasdas da
дБ <> скрипка здесь