SQL aggregate functions are functions that perform a calculation on a set of values and return a single value. These functions are commonly used with the SELECT statement to compute summaries of data in a database. Here are some of the most commonly used SQL aggregate functions:
COUNT(): Returns the number of rows that match a specified condition.
SELECT COUNT(*) FROM table_name;
SELECT COUNT(column_name) FROM table_name WHERE condition;
SUM(): Returns the sum of values in a numeric column.
SELECT SUM(column_name) FROM table_name WHERE condition;
AVG(): Returns the average of values in a numeric column.
SELECT AVG(column_name) FROM table_name WHERE condition;
MIN(): Returns the minimum value in a column.
SELECT MIN(column_name) FROM table_name WHERE condition;
MAX(): Returns the maximum value in a column.
SELECT MAX(column_name) FROM table_name WHERE condition;
These functions can also be used together with the GROUP BY clause to perform aggregate calculations on groups of rows. For example:
SELECT column_name, SUM(sales) FROM table_name GROUP BY column_name;
This would return the sum of sales for each unique value in the column_name column.