You are given the following SQL statement. SELECT e.employee_id, e.salary FROM employees e WHERE e.salary > (   SELECT AVG(s.salary)   FROM employees s   WHERE s.department_id = e.department_id ); Which of the following queries correctly rewrites this logic using an uncorrelated approach, such as a join or uncorrelated subquery or subquery factoring?Single choice

A

SELECT e.employee_id, e.salary FROM employees e JOIN employees s ON e.department_id = s.department_id WHERE e.salary > AVG(s.salary);

B

WITH dept_avg AS (   SELECT department_id, AVG(salary) AS avg_salary   FROM employees   GROUP BY department_id ) SELECT e.employee_id, e.salary FROM employees e JOIN dept_avg d ON e.department_id = d.department_id WHERE e.salary > d.avg_salary;

C

SELECT employee_id, salary FROM employees WHERE department_id IN (   SELECT department_id   FROM employees   GROUP BY department_id   HAVING AVG(salary) < salary );

D

SELECT employee_id, salary FROM employees WHERE salary > (   SELECT MAX(salary)   FROM employees   WHERE department_id = employees.department_id );

Log in for full answers

We've collected over 50,000 authentic original questions and detailed explanations from around the globe. Log in now and get instant access to the answers!

More Practical Tools for Students Powered by AI Study Helper

Join us and instantly unlock extensive past papers & exclusive solutions to get a head start on your studies!