recategorized
1,595 views
2 votes
2 votes

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:

  1. Find the highest paid employee who earns more  than the average salary of all employees of his company.
  2. Find the highest paid employee who earns more  than the average salary of all  the employees of all the companies.
  3. Find all employees who earn more than the average salary of all employees all the companies.
  4. Find all employees who earn more than the average salary of all employees of their company.
recategorized

6 Answers

1 votes
1 votes

INNER QUERY:

For a given company say "ABC" ,this returns all the average salary of all the employees of ABC.

OUTER QUERY:

This returns the name of employees whose salary is greater than the average salary of his company(returned by inner query).

Hence option 4 is the answer

0 votes
0 votes

Option 4.

It doesnot select the higest paid employee, as MAX is not used.. It just selects employee names who ears more than the avg salary of all employee of their company only.

T.company_name= S. Company_name  ... so employee from all companies will not be considered.

0 votes
0 votes

Ans (D) Finds all employees who earn more than the average salary of all employees of their company

Answer:

Related questions

1 votes
1 votes
3 answers
4
go_editor asked Jan 31, 2017
8,521 views
If following sequence of keys are inserted in a B+ tree with K(=3) pointers:8, 5, 1, 7, 3, 12, 9, 6Which of the following shall be correct B+ tree?