In MySQL, the COUNT(), AVG(), and SUM() functions are aggregate functions used to perform calculations on sets of values. Here's a breakdown of each:
Note: they are not case-sensitive, so you can also write as count(),avg(),sum().
1. COUNT()
2. AVG()
-
Purpose: Returns the average value of a numeric column (ignores NULLs).
-
Syntax:SELECT AVG(column_name) FROM table_name;
-
Example:SELECT AVG(salary) FROM employees;
3. SUM()
-
Purpose: Returns the total sum of a numeric column (ignores NULLs).
-
Syntax:SELECT SUM(column_name) FROM table_name;
-
Example:SELECT SUM(salary) FROM employees;