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

Nth maximum salary


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
muraliksnv

New User


Joined: 07 May 2005
Posts: 3

PostPosted: Sun May 08, 2005 4:29 pm
Reply with quote

HI ALL,

1.WHAT IS THE QUERY FOR N th maximum salary in a table employee?please help me.
Back to top
View user's profile Send private message
priya

Moderator


Joined: 24 Jul 2003
Posts: 568
Location: Bangalore

PostPosted: Sun May 15, 2005 11:42 pm
Reply with quote

Search the Forum. This Question is asked atleast once in a week.
Back to top
View user's profile Send private message
i413678
Currently Banned

Active User


Joined: 19 Feb 2005
Posts: 112
Location: chennai

PostPosted: Mon May 16, 2005 5:18 pm
Reply with quote

Hi,

This can be done in two ways using
1.subquery and
2.correlated subquery.

subquery:

1st highest salary : select max(sal) from emp;

2nd highest salary :

select max(sal) from emp where sal < ( select max(sal) from emp);

correlated subquery:

select sal from emp a where
n = ( select count(*) from emp b where a.sal<=b.sal);

replace the n value as 1 for first highest salary , 2 for 2nd highest salary, 3 for third highest salary and so on and so forth.


any doubts please let me know.

pavan
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts SORT ERROR PARAMETER VALUE EXCEEDS M... DFSORT/ICETOOL 12
No new posts Increase the Maximum Length of LRECL ... JCL & VSAM 5
No new posts Logic to skip Maximum time-stamp and ... DB2 2
No new posts What is the maximum number of sort wo... SYNCSORT 2
No new posts How to find the maximum value of a pa... IMS DB/DC 8
Search our Forums:

Back to Top