IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to find the nth maximim salary from a employee table


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
dilpreet

New User


Joined: 18 Mar 2008
Posts: 34
Location: INDIA

PostPosted: Wed Jul 15, 2009 1:23 pm
Reply with quote

in a employee table i need to find the 6th maximum salary. what would be the query for this?
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Wed Jul 15, 2009 2:07 pm
Reply with quote

select max(salary) from emp_table where salary<select max(salary) from emp_table where salary <................Repeat how much you want to go back.............<select max(salary) from emp_table
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Jul 15, 2009 2:41 pm
Reply with quote

Hi
Use below query..
Code:

SELECT col1                               
FROM tab1 E1                         
WHERE ( 6 =                                         
( SELECT COUNT ( DISTINCT ( E2.col1 ) )   
FROM tab1 E2                         
WHERE E2.col1 >=E1.col1));     
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Wed Jul 15, 2009 3:24 pm
Reply with quote

Hi dilpreet
Sambhaji has provided better way to implement it.
i had only seen till 2nd max salary icon_biggrin.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top