Wednesday, 4 June 2014

How to get the 5th highest value from a table

How to get the 5th highest value from a table?

Table:tblEmp
Fields Emp_Name,Emp_Salary

Emp_Name Emp_Salary
A 25000
B 35000
C 12000
D 50000
E 14000
F 18000
G 28000
H 50500
I 40000

From this table I want to konw who is getting 5th highest salary?


SELECT ROWNUM NUM_K, K.* FROM (SELECT ROWNUM NUM_M, M.*
FROM ( select A.EMPLID,A.EFFDT
from ( select * from ps_job where emplid = 'FHQ4' ORDER BY EFFDT DESC ) A
WHERE ROWNUM <= Variable ) M
ORDER BY EFFDT ASC ) K
WHERE ROWNUM <=1


Note :Where varaiable is the nth largest u want

1 comment:

  1. virtualnuggets offering oracle dba online training,corporate training services.

    Disaster Recover:--

    rman>backup database include current controlfile plus archivelog;
    rman>backup spfile;
    target> select name from v$datafile;
    $rm dev/data/*
    Sql>select member from v$logfile;
    $rm dev/log/log/*
    Sql>select name from v$controlfile;
    $rm dev/control/*
    $rm $ORACLE_HOME/dbs/spfiledev.ora
    $rm $ORACLE_HOME/dbs/initdev.ora
    Rman>startup nomount force;
    Rman>restore spfile;
    Rman>startup nomount force;
    Rman>restore controlfile;
    Rman>sql ‘alter database mount’;
    Rman>restore database;
    Rman>list backup of database;
    Rman>list backup of archivelog all;
    Rman>recover database until logseq number;
    Rman>sql ‘alter database open resetlogs’;

    ReplyDelete