Search code examples
kdb

kdb/Q How to renumber rows in table?


If I have a table like the one below:

Iteration Score
1 20
2 87
3 10

I reordered by Score descending:

ordered: `Score desc first_table;

Iteration Score
2 87
1 20
3 10

How can I then renumber the Iteration column, so the output is something like below? I am thinking of creating a new column that gets the index # of every row, then replacing the original Iteration column.

Iteration Score
1 87
2 20
3 10

Solution

  • You can sort the columns not the table:

    update asc Iteration, desc Score from tab