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 

Sum of 3 columns

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


Joined: 02 Feb 2005
Posts: 97
Topics: 36

PostPosted: Wed Jun 08, 2005 12:27 am    Post subject: Sum of 3 columns Reply with quote

Hi all,

i need to write a DB2 query which will fetch all the members whose :-

1) sum of three columns is zeroes

E.X :- Select all members where sum of ( column 1 + column 2 + colum3) = 0

Thanks,
Tattva
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: Wed Jun 08, 2005 4:47 am    Post subject: Reply with quote

tattva,

Try this


Code:

SELECT A.*
  FROM (SELECT MEMBER
              ,SUM(COL1 + COL2 + COL3) TOT
          FROM TABLE
         GROUP BY MEMBER) A
 WHERE A.TOT = 0
 ;


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
tattva
Beginner


Joined: 02 Feb 2005
Posts: 97
Topics: 36

PostPosted: Thu Jun 09, 2005 1:17 am    Post subject: Reply with quote

Hi Kolusu,

But this is taking a lot of time.

Let me mention here that primary key on the table are member, ssn and 3 more colums.

Thanks
Tattva
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: Thu Jun 09, 2005 8:27 am    Post subject: Reply with quote

tattva,

I am sorry for misunderstanding your Question. I re-read it once again and I am assuming that you have 5 colums say

Code:

MEMBER
SSN
COL_AMT1
COL_AMT2
COL_AMT3


I assuming that you want all records when
Code:

COL_AMT1 + COL_AMT2  + COL_AMT3 = 0


If that is right then you can use the following SQL

Code:

SELECT A.*
  FROM (SELECT MEMBER
              ,SSN
              ,(COL_AMT1 + COL_AMT2 + COL_AMT3) TOT
          FROM TABLE) A
 WHERE A.TOT = 0
 ;


Hope this helps...

Cheers

kolusu
_________________
Kolusu
www.linkedin.com/in/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