Oracle Database 12c: SQL Fundamentals — Question 24

You need to write a SQL statement that returns employee name, salary, department ID, and maximum salary earned in the department of the employee for all employees who earn less than the maximum salary in their department.
Which statement accomplishes this task?

Answer options

Correct answer: B

Explanation

Option B is correct because it correctly retrieves the employee's name, salary, department ID, and the maximum salary per department, filtering for those earning less than that maximum. Option A is incorrect as it attempts to use MAX(sal) without a proper subquery for maximum salary. Option C does not link the department ID to the maximum salary correctly, and option D has a syntax issue with the reference to 'a.sal' which is not defined in the outer query.