SQL SUM() Function
SQL SUM() function returns the total sum of all values of a numeric column in a table. You can use SUM function with number values only and also NULL values are ignored during addition.
Syntax
SELECT SUM(columnName)
FROM TableName
We will consider couple of examples from table tblNewStudents.
Let’s take sum of Fees column from tblNewStudents table.
SELECT SUM(Fees) AS FEES FROM tblNewStudents
You can also filter the output with WHERE clause as given below.
SELECT SUM(Fees) AS FEES FROM tblNewStudents WHERE Fees >= 25000
Here, we have calculated sum of fees greater than or equal to 25000 from tblNewStudents table.
Reference: Manzoor Siddiqui [www.SQLServerLog.com]