EasyGROUP BY & Aggregation

Find average salary by job title

The query

SQL
SELECT
  job_title,
  COUNT(*) AS headcount,
  ROUND(AVG(salary), 0) AS avg_salary,
  MIN(salary) AS min_salary,
  MAX(salary) AS max_salary
FROM employees
WHERE job_title IS NOT NULL
GROUP BY job_title
ORDER BY avg_salary DESC;
Tested against PostgreSQL 16

Note

Multiple aggregates in one query — very efficient as table is scanned only once.

Tables referenced