There is a table in which identifiers do not go in order:
CREATE TABLE random(ID INT primary key , Value INT unique ) INSERT INTO random values (1,1), (2,3), (10,7), (4,10), (5,16), (6,17), (17,33), (8,21), (67,27), (11,41), (99,25), (12,13), (13,23), (14,29), (1000,9)
It is necessary to create an additional row numbering column without using the row_number()
function
My attempts:
Generated numbering like this:
select id, value, count(*) over (partition by 1 order by id ) as rnum from random
but this request sorts by key, and the original order is needed.
Is it possible to somehow glue the rnum
column to the right "to the original query "select * from random"
?
Updated table can not be changed; "splicing" is needed in the query, or another query in which, for example, you can refer to line No. 7
rank()
- Saidolim