Junior — Middle
What aggregate functions are available for use with the GROUP BY operator in SQL?
sobes.tech AI
Answer from AI
In SQL, the GROUP BY operator is often used with aggregate functions to compute summary values for groups. The main aggregate functions are:
- COUNT() — counts the number of rows in a group.
- SUM() — calculates the sum of values in a group.
- AVG() — computes the average value.
- MIN() — finds the minimum value.
- MAX() — finds the maximum value.
Example:
SELECT department, COUNT(*) AS employee_count, AVG(salary) AS avg_salary
FROM employees
GROUP BY department;
This query groups employees by department and shows the number of employees and the average salary in each department.