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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts find particular member name in PDS us... ravi243 CLIST & REXX 10 Mon Dec 19, 2016 6:44 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


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