Search code examples
mysqlsqlsql-order-bysql-updatedrizzle

renumber(set column to rank) a column after order by on that column


in sql, i want to do something like

update table set col = rank(col) order by col

how do i do this ?

Purpose :

currently the col has extreme values, like -14000, 23, 4000, 23000 ... they are used in asc, desc sort but when i plot them on a slider, having say 10 positions, each slider position has highly uneven data, so to even it out i wish to renumber the column,

-14000 becomes 0
23 becomes 1
4000 becomes 2

and so on


Solution

  • Used this :

    update table set col = (select count(*) from (select col from table) as temptable where temptable.col <table.col );