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 third largest element in a table?

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

New User


Joined: 31 Jan 2007
Posts: 56
Location: banglore

PostPosted: Sat May 19, 2007 1:17 pm    Post subject: how to get third largest element in a table?
Reply with quote

hi,

can any one please tell me how to get third largest element in a table
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat May 19, 2007 7:33 pm    Post subject:
Reply with quote

Hello,

Set up a cursor to SELECT, ORDER BY DESC, and then use the 3rd result fetched.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Sun May 20, 2007 8:03 am    Post subject: Re: how to get third largest element in a table?
Reply with quote

krishna_mf wrote:
hi,

can any one please tell me how to get third largest element in a table


Code:
SELECT MAX(ELEMENT) FROM TABLE
WHERE ELEMENT < (SELECT MAX(ELEMENT) FROM TABLE)
 


That will get you the second largest element, you should be able to expand that to get the third largest.
Back to top
View user's profile Send private message
skkp2006

New User


Joined: 14 Jul 2006
Posts: 93
Location: Chennai,India

PostPosted: Mon May 21, 2007 9:34 am    Post subject: Re: how to get third largest element in a table?
Reply with quote

Try this out......

Select * From Table A Where
(N-1) = (Select Count(Distinct(B.Empid)) From Table B Where
B.Empid > A.Empid)

Regards
Syam
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 SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Command UNIQUE CONSTRAINT on any tabl... rohanthengal DB2 2 Thu Aug 18, 2016 3:48 pm
No new posts Updating online Db2 table kishpra DB2 3 Fri Aug 12, 2016 2:44 pm
No new posts Getting soc4 on internal table in cobol abdulrafi COBOL Programming 13 Fri May 06, 2016 3:39 pm


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