Open In App

UGC-NET | UGC NET CS 2017 Jan – III | Question 11

Consider the following relation:

Works (emp_name, company_name, salary)

Here, emp_name is primary key.
Consider the following SQL query



Select emp_name
From works T
where salary > (select avg (salary)
                from works S
                where T.company _ name = S.company _ name)

The above query is for following :
(A) Find the highest paid employee who earns more than the average salary of all employees of his company.
(B) Find the highest paid employee who earns more than the average salary of all the employees of all the companies.
(C) Find all employees who earn more than the average salary of all employees of all the companies.
(D) Find all employees who earn more than the average salary of all employees of their company.

Answer: (D)
Explanation: Given, schema and SQL query:

Works (emp_name, company_name, salary)

Here, emp_name is primary key.



Select emp_name
From works T
where salary > (select avg (salary)
                from works S
                where T.company _ name = S.company _ name)

Inner Query will compute average salary of company and compare salary with selected employees. So, final outcome is all employees who earn more than the average salary of all employees of their company.

Option (D) is correct.
Quiz of this Question

Article Tags :