Click here to Skip to main content
Rate this: bad
good
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
v2
Rate this: bad
good
Please Sign up or sign in to vote.

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

Solution 1

hi,
 
use the following query, it may help you..
Select Name, ColumnA, ColumnB, Test, TestAA, (ColumnA+ColumnB+Test+TestAA) 'Sum' from yourtableName
 
Regards,
Prakash.T
  Permalink  
v3
Comments
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 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 PIEBALDconsult 110
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2014
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