Quick Search:
 
 Oracle PL/SQL: Show Nth highest value Jump to:  
Category: >> Oracle PL/SQL >> Show Nth highest value  

<< lastnext >>

Snippet Name: Show Nth highest value

Description: Select and display the Nth highest value from a table.

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 02nd, 2009

SELECT LEVEL, MAX('col_name') FROM my_table
WHERE LEVEL = '&n'
CONNECT BY PRIOR ('col_name') > 'col_name')
GROUP BY LEVEL;
 
-- Example :
--
-- Given a table called emp with the following columns:
--   id   number
--   name varchar2(20)
--   sal  number
--
-- For the second highest salary:
 
SELECT LEVEL, MAX(sal) FROM emp
WHERE LEVEL=2
CONNECT BY PRIOR sal > sal
GROUP BY LEVEL
 


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org