Quick Reach
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:
1
|
select sum(emp_sal_paid) as Total_paid_salaries from tbl_emp_salary_paid
|
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:
1
|
select count(*) as Total_records from tbl_emp_salary_paid
|
Leave A Comment?