A company has two tables, departments and employees. Each employee belongs to some department and has a status (status: ACTIVE or INACTIVE) and a salary. Write a single SELECT statement that computes, per department, the average salary of the employees who are currently working (ACTIVE). The result has two columns: - department_name : the department's name - avg_salary : the average salary of that department's active employees Write your query in solution.sql, and pressing 'Run test' runs it against a real database and shows the result table.
This challenge has you write a PostgreSQL SELECT statement for the average salary of the working (ACTIVE) people in each department. Two tables — one of department info, one of staff info — come ready with data, and pressing 'Run test' runs your query against a real database and shows the result table. The result has two columns: one for the department name, one for that department's average.
This problem is about "when joining a table and filtering it overlap, what quietly disappears." A query that sums or averages can look fine on a few common rows, yet give a different answer when one side is empty (a department where nobody is working, for instance). Before trusting such a query, don't just skim a few ordinary departments — run it for real and watch with your own eyes that not a single row drops, even for the data sitting at the edges.