Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Nth maximum salary

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
Author Message
muraliksnv

New User


Joined: 07 May 2005
Posts: 3

PostPosted: Sun May 08, 2005 4:29 pm    Post subject: QUERIES
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
References
priya

Moderator


Joined: 24 Jul 2003
Posts: 624
Location: Bangalore

PostPosted: Sun May 15, 2005 11:42 pm    Post subject:
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    Post subject: query
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
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1