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
 

 

HOW TO GET THE 5TH MAX SALARY USING QUERY?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
shivakumar .b
Warnings : 1

New User


Joined: 11 May 2005
Posts: 18
Location: bangalore

PostPosted: Mon May 23, 2005 12:27 pm    Post subject: HOW TO GET THE 5TH MAX SALARY USING QUERY?
Reply with quote

HI EVERYBODY,
THIS IS B.SHIVAKUMAR.
I KNOW HOW TO GET THE 2ND MAX SALARY BUT I DON'T KNOW HOW TO GET 5TH OR 6TH HIGHEST SALARY.
CAN ANYBODY PLZ TELL ME HOW TO GET THE 5TH MAX SALARY USING QUERY?
THANKS IN ADVANCE.
REGARDS,
B.SHIVAKUMAR
Back to top
View user's profile Send private message

vasanthanc

New User


Joined: 01 Apr 2005
Posts: 58

PostPosted: Mon May 23, 2005 3:20 pm    Post subject:
Reply with quote

go thru the link below

http://ibmmainframes.com/viewtopic.php?t=1472

this question has already been answered. kindly search the forum before u post a question.
Back to top
View user's profile Send private message
shivakumar .b
Warnings : 1

New User


Joined: 11 May 2005
Posts: 18
Location: bangalore

PostPosted: Tue May 24, 2005 11:42 am    Post subject: Re: HOW TO GET THE 5TH MAX SALARY USING QUERY?
Reply with quote

hello vasanth, thanks for u r reply.
but still i didnot understand the query for finding Nth maximum salary.
I was not clear about that query, can u xplain me in detail.
thanks in advance.
regards,
b.shivakumar
Back to top
View user's profile Send private message
kkumarv

New User


Joined: 13 May 2005
Posts: 20
Location: Bangalore/India

PostPosted: Tue May 24, 2005 2:28 pm    Post subject:
Reply with quote

SELECT DISTINCT (SALARY)
FROM EMPTABLE A
WHERE 5 = (SELECT COUNT (DISTINCT (B.SALARY)) FROM EMPTABLE B
WHERE A.SALARY <= B.SALARY);
Back to top
View user's profile Send private message
vasanthanc

New User


Joined: 01 Apr 2005
Posts: 58

PostPosted: Tue May 24, 2005 4:00 pm    Post subject:
Reply with quote

First u shud understand the sub query

SELECT COUNT (DISTINCT (B.SALARY)) FROM EMPTABLE B
WHERE A.SALARY <= B.SALARY

In the sub query we are finding the count of employees in emp table having their salary less than or equal to X. (imagine X as some value. The X is taken from emptable of main query and it will be iterated for each salary value).

Now come to main query. It just finds the salary from employee table when the count from sub query matches N (in ur case 5).


Hope u understand...
Back to top
View user's profile Send private message
jkbytes

Active User


Joined: 19 Feb 2005
Posts: 141
Location: South Africa

PostPosted: Wed May 25, 2005 10:45 am    Post subject: Re: HOW TO GET THE 5TH MAX SALARY USING QUERY?
Reply with quote

QUERY : TO FIND OUT THE Nth HIGHEST SALARY

SELECT EMPSAL FROM EMPNEW E1 WHERE n =
(SELECT COUNT(*) FROM EMPNEW E2
WHERE E1.EMPSAL<=E2.EMPSAL);


I GUESS THIS IS ANOTHER WAY OF GETTING THE Nth SALARY.

Thanks & Regards,

JKBYTES.
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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


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