Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Select query to display sum of all columns in a table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
Author Message
pradeep_123

New User


Joined: 21 Nov 2007
Posts: 6
Location: bhubaneswar

PostPosted: Sat Aug 23, 2008 12:02 pm    Post subject: Select query to display sum of all columns in a table
Reply with quote

hi all,

i am having a table which contain 3 records.let table name be EMP and columns are C1,C2 C3 which contains integer values.

i want to get sum of all rows of all columns. Suppose assume that C1 ,C2,C3 contains values (1,2,3) ,(4,5,6) and (7,8,9)

(1+2+3+4+5+6+7+8+9)=45.

i want total as single value as 45.
Can any one please help me to get the query.

This is my first post in this form.if any mistakes plz excuse.
Back to top
View user's profile Send private message
References
Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 111
Location: India

PostPosted: Sat Aug 23, 2008 2:06 pm    Post subject:
Reply with quote

Why cant you try the below query:

Select sum(c1) + sum (c2) + sum (c3)
from table


Thanks,
Prajesh V P
Back to top
View user's profile Send private message
pradeep_123

New User


Joined: 21 Nov 2007
Posts: 6
Location: bhubaneswar

PostPosted: Sat Aug 23, 2008 2:28 pm    Post subject: Reply to: Select query to display sum of all columns in a ta
Reply with quote

Thank you for ur answer.

but ,I think it will be very difficult if the table contains more than 10 columns .
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 1618
Location: germany

PostPosted: Sat Aug 23, 2008 4:43 pm    Post subject: Re: Reply to: Select query to display sum of all columns in
Reply with quote

pradeep_123 wrote:
... but ,I think it will be very difficult if the table contains more than 10 columns .


and why do you think that?
Back to top
View user's profile Send private message
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 8643
Location: 221 B Baker St

PostPosted: Sat Aug 23, 2008 5:52 pm    Post subject:
Reply with quote

Hello,

pradeep wrote:
i want to get sum of all rows of all columns.


Quote:
Why cant you try the below query:
Select sum(c1) + sum (c2) + sum (c3)


pradeep wrote:
but ,I think it will be very difficult if the table contains more than 10 columns .

Your concern is not clear to us. To sum the columns, you would need to name them . . . Where does the difficulty come in?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1