I have a query which returns some values (att1
). I would like also to have next to it the values which would represent a sorted order of att1
. Somethin
Assuming a table name of table1
, The following should yield the desired result:
select a.att1, (select count(*) from table1 b where b.att1 <= a.att1) as att2
from table1 a;
For every record, the query calculates the number of records less than or equal to the current record, which is then output as the sort index.