Click here to Skip to main content
11,493,154 members (61,470 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# MySQL
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 Smile | :)
Posted 28-Feb-13 21:16pm
Edited 28-Feb-13 21: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 at 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 at 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 at 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
0 Sergey Alexandrovich Kryukov 419
1 Maciej Los 286
2 F-ES Sitecore 224
3 KarstenK 210
4 CPallini 208
0 Sergey Alexandrovich Kryukov 10,132
1 OriginalGriff 8,630
2 Sascha Lefèvre 3,624
3 Maciej Los 3,392
4 Richard Deeming 2,500

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2015
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