Click here to Skip to main content
15,849,829 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai all,

How get sum of Column

Table structure
=============================
Field ------------ Data Type
=============================
Name ------------ varchar(255)
Column A ------ double unsigned
Column B ------ double unsigned
TEST ------------- double YES
TEST AA --------- double YES

=============================
Demo Value for table

XXXX 10 20 30 40
YYYY 5 10 15 20



I Need the final result as below
Sum of all Double Data Type Column

name | Column A | Column B | TEST | TEST AA | Sum
==================================================
XXXX -------10------------20--------30------40--------100
YYYY ---------5------------10--------15------20---------50

* Please note that the Field name contain 'white space' its don't avoid.

Im using MySql.

Thanks :)
Posted
Updated 28-Feb-13 21:18pm
v2

Hi,

I am updating the solution 1.
SQL
Select Name, ColumnA, ColumnB, Test, TestAA, (ISNULL(ColumnA, 0) + ISNULL(ColumnB, 0)  + ISNULL(Test, 0) + ISNULL(TestAA, 0)) AS 'SUM' from yourtableName


if you do not use ISNULL function then, if anyone value goes NULL then whole sum will go null. so, using isnull function we will replace null value with 0.

hope it helps.
 
Share this answer
 
Comments
indhukanth 1-Mar-13 3:23am    
Hi karthik,
thanks for you Help..
but its not working Here ...
i cahnage ISNULL with IFNULL thats work greatly... !! thankz :)
Karthik Harve 1-Mar-13 3:28am    
Welcome.!
hi,

use the following query, it may help you..
SQL
Select Name, ColumnA, ColumnB, Test, TestAA, (ColumnA+ColumnB+Test+TestAA) 'Sum' from yourtableName


Regards,
Prakash.T
 
Share this answer
 
v3
Comments
Karthik Harve 1-Mar-13 2:22am    
[Edit] pre tags added

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900