HomeInterview QuestionsWrite an SQL query that lists all departments wher…

Write an SQL query that lists all departments where the average salary is greater than 60,000.

🟡 Medium Coding Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

Group the employees by department, calculate the average salary, and filter with HAVING:

sql
SELECT department,
       AVG(salary) AS avg_salary
FROM   Employees
GROUP BY department
HAVING AVG(salary) > 60000;

This query performs a single aggregation pass over the table, so its time complexity is O(n). It returns each department that meets the threshold along with the computed average salary.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500