How to use SQL aggregate functions

SQL Aggregate functions

The SQL comes up with many aggregate functions that allow you to perform calculations on the columns data and return the aggregated value. These SQL aggregate functions can work in the simple SQL select statement or with the group by clause in the select statement to return single or group based calculated values.

Some of the commonly used SQL aggregate functions are listed below along with the links to their respective chapters.

Commonly used aggregate SQL functions

Count(): The count SQL function returns the total number of rows excluding the Null values.

Sum(): The Sum function returns the total calculated values of the given numeric column.

Max(): Max function returns the maximum value in the given column name.

Min(): Returns minimum value in the given column.

Avg(): The AVG function returns the average value of the given numeric column.

Examples of using aggregate functions in SQL

Following are a few examples of aggregate functions in SQL. In our examples, we will use the tbl_emp_salary_paid table that stores employees salaries.

To see table structure and data, click the link below before going to aggregate function examples. 

See structure and data in tbl_emp_salary_paid

Example of using Sum() function

The following SQL query will return the sum of all salaries paid to the employees, stored in the emp_sal_paid column.

The sum function query:


See the Sum SQL function query

SQL Count() function example

The following SQL query will return the total number of rows in the tbl_emp_salary_paid table.

The SQL count function:


See the SQL query and result of above query

Also see SQL count | SQL max | SQL sum

Was this article helpful?

Related Articles

Leave A Comment?