12,075,783 members (34,552 online)
Rate this:
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 28-Feb-13 21:16pm
Edited 28-Feb-13 21:18pm
v2

Rate this:

## Solution 2

Hi,

I am updating the solution 1.
`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.
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.!
Rate this:

## Solution 1

hi,

```Select Name, ColumnA, ColumnB, Test, TestAA, (ColumnA+ColumnB+Test+TestAA) 'Sum' from yourtableName
```

Regards,
Prakash.T
v3
Karthik Harve 1-Mar-13 2:22am

Top Experts
Last 24hrsThis month
 Richard MacCutchan 469 OriginalGriff 361 F-ES Sitecore 165 Dave Kreskowiak 125 Member 11712753 124
 Dave Kreskowiak 2,836 OriginalGriff 2,805 Richard MacCutchan 2,174 CPallini 1,607 CHill60 1,379