Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
how to find the nth maximim salary from a employee table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
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    Post subject: how to find the nth maximim salary from a employee table
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    Post subject: Reply to: how to find the nth maximim salary from a employee
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm
No new posts PC (UTF-8) -> z/OS (EBCDIC) -> ... prino All Other Mainframe Topics 4 Fri Sep 01, 2017 1:47 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us