QuestionQ264

VerifiedUsing Subqueries to Solve Queries

Review the description of the EMPLOYEES table:

Question Image

Which two queries return every employee row whose salary exceeds the average salary for that employee’s department?

Choose two
Explanation

A correlated scalar subquery can compare each employee’s salary with the single AVG(salary) value computed for that employee’s matching department_id. An analytic AVG(salary) OVER (PARTITION BY department_id) calculates the departmental average for every employee row; placing that calculation in an inline view allows the outer query to filter on it. Oracle requires analytic-function filtering to be performed in an outer query, because analytic processing occurs after WHERE.

Learn more

Community Discussion

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