Click here to Skip to main content
12,998,654 members (130,414 online)
Rate this:
Please Sign up or sign in to vote.
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 20:16pm
Updated 28-Feb-13 20:18pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100