1z0-071 Exam QuestionsBrowse all questions from this exam

1z0-071 Exam - Question 63


Examine the description of the EMPLOYEES table:

Which two queries return all rows for employees whose salary is greater than the average salary in their department? (Choose two.)

A.

B.

C.

D.

E.

Show Answer
Correct Answer:

To return all rows for employees whose salary is greater than the average salary in their department, we need to compare each employee's salary to the average salary of their respective department. The correct query options here would be using subqueries or analytic functions to achieve this. The correct answers are B and E. B uses a correlated subquery, which calculates the average salary for each department and compares it with the current employee's salary. E uses a window function to calculate the average salary for each department and then filters results based on the comparison. Both methods are valid and correctly solve the problem. Therefore, the correct answers are B and E.

Discussion

2 comments
Sign in to comment
Poke90
Mar 8, 2023

IN E, the column alias avg_salary from the sub query is used in the WHERE clause of the main query. Is that allowed?

Eltelwany
Mar 14, 2023

Yes, it is allowed. It follows from the order of the execution. Since the engine would execute the subquery first, it already knows what the alias refers to.

ArslanAltaf
Apr 16, 2024

B & D is correct only. E is not

ArslanAltaf
Apr 17, 2024

Correction - B, D and E all worked. All tested

ogi33
Apr 26, 2024

D execute but gives no corect data