sql - how to give rank serially -


i have table like

   name          age    -----------------    jagga         25     lipu          25     aswinee       24     lisu          23     ankita        25     jhon          23  

i want out put

   name         age     rank    -------------------------    ankita       25      1     jagga        25      2      lipu         25      3     aswinee      24      4     jhon         23      5      lisu         23      6   

the name , age must have order by clause rank count start 1.

we not know dbms using, so
mysql

set @id := 0; select test.name ,      test.age ,      @id := @id + 1 rank   test order age desc, name; 

ms sql server/oracle/postgresql:

select name ,      age ,      row_number() over(order age desc, name) rank      test order age desc, name 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -