Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ 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
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    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

priya

Moderator


Joined: 24 Jul 2003
Posts: 568
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the maximum number of sort wo... Pravina M SYNCSORT 2 Mon Mar 14, 2016 4:51 pm
No new posts How to find the maximum value of a pa... Susheel singh IMS DB/DC 8 Mon Mar 24, 2014 11:39 am
No new posts Select maximum value of Sequence Num... Vijayshyale DB2 1 Fri Jan 31, 2014 8:11 am
No new posts Get maximum value of 2 different fields aditya_gorti DFSORT/ICETOOL 10 Wed Nov 27, 2013 7:36 pm
No new posts Maximum number of I/O PCBs in a COBOL... guruji Mainframe Interview Questions 7 Mon Nov 18, 2013 11:25 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us