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

Select query to display sum of all columns in a table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pradeep_123

New User


Joined: 21 Nov 2007
Posts: 9
Location: bhubaneswar

PostPosted: Sat Aug 23, 2008 12:02 pm
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
Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Sat Aug 23, 2008 2:06 pm
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: 9
Location: bhubaneswar

PostPosted: Sat Aug 23, 2008 2:28 pm
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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Aug 23, 2008 4:43 pm
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

Moderator Emeritus


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

PostPosted: Sat Aug 23, 2008 5:52 pm
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts RC query -Time column CA Products 3
No new posts Remote Unload of CLOB Columns DB2 6
No new posts Multiple table unload using INZUTILB DB2 2
Search our Forums:

Back to Top