3 min read•august 6, 2024
Aggregate functions in SQL are powerful tools for summarizing data. They allow you to rows, calculate sums and averages, and find and values. These functions are essential for analyzing large datasets and extracting meaningful insights.
Grouping and filtering enhance the capabilities of aggregate functions. The clause organizes data into categories, while filters grouped results. Together, they enable complex data analysis and help uncover patterns within your database.
[SELECT](https://www.fiveableKeyTerm:select) COUNT(*) [FROM](https://www.fiveableKeyTerm:from) employees;
counts the number of rows in the employees tableSELECT SUM(salary) FROM employees;
calculates the total sum of all salaries in the employees tableSELECT AVG(price) FROM products;
calculates the average price of all productsSELECT MIN(hire_date) FROM employees;
returns the earliest hire date among all employeesSELECT MAX(salary) FROM employees;
returns the highest salary among all employeesSELECT department, COUNT(*) FROM employees GROUP BY department;
counts the number of employees in each departmentSELECT department, AVG(salary) FROM employees GROUP BY department;
calculates the average salary for each departmentSELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) > 50000;
returns the departments with an average salary greater than $50,000SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) > 10;
returns the departments with more than 10 employees