QuestionQ54

VerifiedUsing Subqueries to Solve Queries

You need to write a SQL statement that returns the employee name, salary, department ID, and the highest salary earned in that employee's department for all employees whose salary is below the maximum salary in their department.

Which statement completes this task?

Explanation

A derived table that groups employees by dept_id can calculate each department's MAX(sal). Joining that result back to the employee rows on dept_id associates every employee with the maximum salary in the same department, and filtering with a.sal < b.maxsal retains only employees who earn less than that maximum.

Community Discussion

No comments yet. Be the first to start the discussion!