Oracle adds a sequence number after sorting the result and returns the sequence number of a record

    First of all, the serial number in oracle generally uses rownum

select rownum,t.* from T_USER_BASICINFO t

   

 But if you need to sort by one of the fields, rownum cannot be sorted in order. Here is sorted by u_level field

select rownum,t.* from T_USER_BASICINFO t order by t.u_level

    Solution:

The first:

select  rownum,a.*
from (select t.* from T_USER_BASICINFO t
     order by t.u_level
) a


The second:

select row_number() over (order by t.u_level) rn,t.*  from T_USER_BASICINFO t

In addition, if you want to know the sort number of one of the records in the result, use

select tt.rn,tt.* from
 (select row_number() over (order by t.u_level) rn,t.*  from T_USER_BASICINFO t ) tt
where tt.user_id ='10000000044'


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324859197&siteId=291194637