Back to questions

Department vs. Company Salary [FAANG SQL Interview Question]


You work as a data analyst for a FAANG company that tracks employee salaries over time. The company wants to understand how the average salary in each department compares to the company's overall average salary each month.

Write a query to compare the average salary of employees in each department to the company's average salary for March 2024. Return the comparison result as 'higher', 'lower', or 'same' for each department. Display the department ID, payment month (in MM-YYYY format), and the comparison result.


employee_idintegerThe unique ID of the employee.
namestringThe full name of the employee.
salaryintegerThe salary of the employee.
department_idintegerThe department ID of the employee.
manager_idintegerThe manager ID of the employee.

Example Input:

1Emma Thompson380016
2Daniel Rodriguez223017
3Olivia Smith700018
5Sophia Martinez1750111


salary_idintegerA unique ID for each salary record.
employee_idintegerThe unique ID of the employee.
amountintegerThe salary of the employee.
payment_datedatetimeThe date and time when the salary was paid to the employee.

Example Input:

11380001/31/2024 00:00:00
22223001/31/2024 00:00:00
33700001/31/2024 00:00:00
44680001/31/2024 00:00:00
55175001/31/2024 00:00:00

Example Output:


The output indicates that the average salary of Department 1 is lower than the company's average salary for January 2024.

The dataset you are querying against may have different input & output - this is just an example!

PostgreSQL 14