IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to get third largest element in a table?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Sat May 19, 2007 7:33 pm
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
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
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 All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts count contained values of several col... DB2 5
No new posts To join 2 tables and to join 3rd tabl... DB2 8
No new posts Create a specific record/file based o... SYNCSORT 8
No new posts Extract ISPF table column headings CLIST & REXX 2
No new posts Unload and Load ISPF Table TSO/ISPF 4
Search our Forums:


Back to Top