SQL common aggregate functions include: COUNT() Calculate the number of rows SUM() Sum AVG() Find the average MIN() Find the minimum value MAX() Find the maximum value
Commonly used aggregate functions in SQL
The aggregate functions in SQL (Structured Query Language) are used to operate on a set of values and combine them Aggregate into one or more values. The most common aggregate functions include:
Other commonly used aggregate functions:
Use aggregate functions:
Aggregation functions are usually used in the GROUP BY clause of the SELECT statement, which groups query results by specified columns. For example, the following query calculates the average sales for each group:
<code>SELECT department_name, AVG(sales) FROM sales GROUP BY department_name;</code>
Aggregate functions can also be used in the HAVING clause, which filters groups. For example, the following query returns only departments with average sales greater than 1000:
<code>SELECT department_name, AVG(sales) FROM sales GROUP BY department_name HAVING AVG(sales) > 1000;</code>
The above is the detailed content of Common aggregate functions in sql. For more information, please follow other related articles on the PHP Chinese website!