Skip to content
Related Articles

Related Articles

UGC-NET | UGC NET CS 2017 Jan – III | Question 11
  • Last Updated : 02 Apr, 2018
GeeksforGeeks - Summer Carnival Banner

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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :