Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 6968
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 Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts display the sign only if the value is... useit DFSORT/ICETOOL 3 Wed Oct 04, 2017 5:53 pm
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Binary to display characters Roy Ware SYNCSORT 3 Tue Sep 19, 2017 8:46 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us