Question 63Asked in UGC NET Computer Science, June 2017 (Paper II & III, Selected Questions)

Consider the following relation : Works (emp_name, company_name, salary)

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 if for following :
  1. AFind the highest paid employee who earns more than the average salary of all employees of his company
  2. BFind the highest paid employee who earns more than the average salary of all the employees of all companies
  3. CFind all employees who earn more than the average salary of all employees of all the companies
  4. DFind all employees who earn more than the average salary of all employees of their company
Show answerHide answer

Correct answer: (D) Find all employees who earn more than the average salary of all employees of their company

Explanation

The correlated subquery computes the average salary of the employee's own company (T.company_name = S.company_name). The query does not use max, so it does not select only the highest paid employee; it selects all employees who earn more than the average salary of their company.

From UGC NET Computer Science PYQ, June 2017 (Paper II & III, Selected Questions)

This is question 63 of UGC NET Computer Science PYQ, June 2017 (Paper II & III, Selected Questions). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.