Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ 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
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    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

Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
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: 9
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

Global Moderator


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

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

Site Director


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

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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts unload data from table with lob columns farhad_evan DB2 0 Sat Apr 22, 2017 1:32 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts Display FTP Session Count within TSO Yolanda Harvey TSO/ISPF 3 Fri Mar 10, 2017 10:31 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us