SQL SUM() Function


The SQL SUM() is a function, and return total sum of a table column from query result.

The SQL SUM() function is supports only numeric column or an numeric field based expression.

It can be used in SQL SELECT statement as well in SQL WHERE clause.


Search Keys

  • sql sum function
  • sql sum
  • sum in sql
  • select sum
  • sql sum of column
  • sql sum rows
  • query sum
  • sum where
  • sql sum two columns
  • sum column sql
  • sql average of sum
  • sql sum multiple columns
  • sql compute sum
  • sql sum row values
  • sum expression

SQL SUM() Syntax

The below syntax is used to make sum of a numeric value or numeric expression.


SELECT SUM(numeric_value or numeric expression);

The below syntax is used to make sum of a specific column from the specific table.


SELECT SUM(column_name or expression) FROM table_name;


Sample Database Table - Employee

ID EmpName Designation Dept JoinYear Salary
1 Ranjani Mai Big Data ASP.Net 2014 15020
2 Harish Karthik Mobile Database MS Access 2013 8090.8
3 Devi Mai Project Manager MySQL 2013 18170.5
4 Pandurengan Relational DBMS SQL Server 2014 11240
5 Vidyavathi SQL Mining PHP 2013 15860
6 Hari Krishnan Project Lead SQL Server 2015 7880
7 Keshavan Big Data SQL Server 2013 7670.2
8 Hanumanthan Sql Team Adminstrator Oracle 2013 5780
9 Bala Murugan SQL Database JQuery 2012 8930.9
10 Rishi Keshan Developer PHP 2012 7880
11 Geetha Sql Team Adminstrator SQL Server 2014 12080
12 Chandra Manager MySQL 2014 6200

SQL SUM() Example - With Single Column

The following SQL SELECT statement find the total salary of all employees from the "Employee" table:


SELECT SUM(Salary) As 'Total Salary' 
FROM Employee;

The result of above query is:

Total Salary
124802.40

SQL SUM() Example - Using Expression Or Formula

The following SQL SELECT statement find the total salary, 20% bonus of salary, and then new total salary of all employees from the "Employee" table:


SELECT 
SUM(Salary) As 'Total Salary', 
SUM((Salary / 100) * 20) As 'Bonus 20%',  
SUM(Salary + ((Salary / 100) * 20)) As 'New Total Salary' 
FROM Employee;

The result of above query is:

Total Salary Bonus 20% New Total Salary
124802.40 24960.48 149762.88

SQL SUM() Example - Using Group By Clause

The following SQL SELECT statement find the total salary by grouping "Dept" column of all employees from the "Employee" table:


SELECT 
Dept, SUM(Salary) As 'Total Salary' 
FROM Employee 
GROUP BY Dept;

The result of above query is:

Dept Total Salary
ASP.Net 15020
JQuery 8930.9
MS Access 8090.8
MySQL 24370.5
Oracle 5780
PHP 23740
SQL Server 38870.2

Search Keys

  • sql sum values
  • sql summary functions
  • sql group sum
  • sql sum group
  • total function
  • sql query total
  • how to count rows in sql
  • sql add column values
  • sql query to add column values
  • aggregate functions in sql
  • sql aggregate functions
  • aggregate query
  • sql aggregate functions examples
  • sql aggregate functions with examples
  • sql aggregate functions list