SQLIntermediate#queries

How do you find employees earning more than their department average?

Compare each row against a window average or a grouped subquery on the same department.

Example
SELECT name, salary FROM (
  SELECT name, salary, AVG(salary) OVER (PARTITION BY dept_id) avg_sal
  FROM employees
) t WHERE salary > avg_sal;

Related Questions

1
SQLIntermediate#joins#queries

How do you find records in table A that are missing in table B?

Open
2
SQLBeginner#datatypes

CHAR vs VARCHAR vs TEXT?

Open
3
SQLAdvanced#performance

What is the difference between an execution plan and EXPLAIN ANALYZE?

Open