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.

SUM Function

Let’s take sum of Fees column from tblNewStudents table.

SELECT SUM(Fees) AS FEES 
FROM tblNewStudents 

SUM Function2

You can also filter the output with WHERE clause as given below.

SELECT SUM(Fees) AS FEES 
FROM tblNewStudents WHERE Fees >= 25000

SUM Function3

Here, we have calculated sum of fees greater than or equal to 25000 from tblNewStudents table.

Reference: Manzoor Siddiqui [www.SQLServerLog.com]

You may also like

You may also like...

Leave a Reply