I keep getting errors with aggregate functions. how do i use group by correctly?

Example:

-- Incorrect usage of aggregate function without GROUP BY
SELECT department, AVG(salary) FROM employees;
Solution:

-- Correct usage of aggregate function with GROUP BY
SELECT department, AVG(salary) 
FROM employees 
GROUP BY department;
When using aggregate functions like AVG, SUM, COUNT, etc., you need to group the results by a column using the GROUP BY clause.

Beginner's Guide to SQL