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
 

 

Tell me the best optimum query to find nth highest salary

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
itssrikanth4u

New User


Joined: 21 Nov 2004
Posts: 9

PostPosted: Sat Dec 11, 2004 5:48 pm    Post subject: Tell me the best optimum query to find nth highest salary
Reply with quote

Hi,

Can any one please tell me the best optimum query to find nth highest salary?

bye
thanx in advance
take care
srikanth
Back to top
View user's profile Send private message

ovreddy

Active User


Joined: 06 Dec 2004
Posts: 211
Location: Keane Inc., Minneapolis USA.

PostPosted: Mon Dec 13, 2004 2:47 pm    Post subject: Here is one way...
Reply with quote

Hi,

Here is a way in which we can find nth max or top n max salaries from emp table...

SELECT SAL FROM EMP A WHERE N<=(SELECT COUNT(DISTINCT SAL) FROM EMP B WHERE A.SAL<=B.SAL);

This is one way to find top n salaries. But execute this and check EXPLAIN results so that u will get exact optimization. If you have any other queries an your mind apply Explain on them and compare... ok

Bye,
Reddy.
Back to top
View user's profile Send private message
jz1b0c

Active User


Joined: 25 Jan 2004
Posts: 160
Location: Toronto, Canada

PostPosted: Mon Dec 13, 2004 11:56 pm    Post subject:
Reply with quote

Srikanth,
This was answered earlier,

SELECT *
FROM TEST.TABLE1 T1
WHERE 5 = ( SELECT COUNT(DISTINCT T2.NUM)
FROM TEST.TABLE2 T2
WHERE T2.NUM >= T1.NUM)
ORDER BY NUM DESC ;;
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 find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts To find out size allocated to a seque... ashek15 JCL & VSAM 15 Thu Apr 27, 2017 9:42 am
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


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