Krivalar Tutorials 
Krivalar Tutorials



SQL sum function to calculate sum of values in a column

<< Previous - SQL AVG() Function

Next - SQL Join >>






SQL SUM() function

The SUM() function calculates the total sum of a selected numeric column.

SQL SUM() Syntax

SELECT SUM(column-name) FROM  Table-name
WHERE condition;

SQL SUM Example

Demo student_mark table from collegedb database.

mysql> SELECT * FROM Student_Mark;
+--------+---------+-----------+------+
| RollNo | Name    | City      | Mark |
+--------+---------+-----------+------+
|    101 | Sakthi  | Chennai   |   80 |
|    102 | Bala    | Chennai   |   86 |
|    103 | Chandra | Bangalore |   89 |
|    104 | Madhan  | Goa       |   80 |
|    105 | Jose    | Kerala    |   82 |
|    106 | Jithu   | Kerala    |   85 |
|    107 | Veni    | Bangalore |   85 |
+--------+---------+-----------+------+
7 rows in set (0.00 sec)

Following query statement add all the values in the Mark column

mysql> SELECT SUM(Mark) FROM Student_Mark;
+-----------+
| sum(Mark) |
+-----------+
|       587 |
+-----------+
1 row in set (0.00 sec)

<< Previous - SQL AVG() Function

Next - SQL Join >>









Searching using Binary Search Tree