MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sql to sum the second max and second min of column

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
butta_mvs
Beginner


Joined: 17 Aug 2003
Posts: 22
Topics: 18

PostPosted: Sun Aug 17, 2003 5:00 am    Post subject: sql to sum the second max and second min of column Reply with quote

I need an sql statement which returns the sum of second max and second min for the value of a column.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Aug 18, 2003 9:10 am    Post subject: Reply with quote

Buttamvs,

Try the following Sql's

Code:

SELECT INTEGER(MAX(A.COLUMN)) +                             
       INTEGER(MIN(B.COLUMN))                               
  FROM TABLE A,                                               
       TABLE B                                                 
 WHERE A.COLUMN < (SELECT MAX(COLUMN) FROM TABLE) 
 AND   B.COLUMN > (SELECT MIN(COLUMN) FROM TABLE);


OR

Code:

SELECT SUM(A.MIN_MAX) FROM                                         
(SELECT INTEGER(MAX(COLUMN)) AS MIN_MAX                       
  FROM TABLE                                                   
 WHERE COLUMN < (SELECT MAX(COLUMN) FROM TABLE)     
 UNION                                                             
SELECT INTEGER(MIN(COLUMN))  AS MIN_MAX                       
  FROM TABLE                                                   
 WHERE COLUMN > (SELECT MIN(COLUMN) FROM TABLE)) A ;


Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group