Reputation: 23
In my table, each row can hold an integer let's call this integer column height
.
for example, the values in this column could be: [5, 4, 0, 1, 9]
I need for this sequence in the example to be rearranged to become: [0, 1, 4, 5, 9]
and then I want these values to become like this: [1, 2, 3, 4, 5]
.
The idea I am trying to write in SQL is to get the minimum at the first time and count how many values are there less than it.
How can I write/translate this idea into an SQL Query?
Upvotes: 0
Views: 271
Reputation: 1269803
You seem to want a ranking:
select t.*, row_number() over (order by height) as height_seqnum
from t
order by height_seqnum;
Upvotes: 1