in Databases recategorized
829 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.
in Databases recategorized
829 views

6 Answers

3 votes
3 votes
I think Option 4
1 vote
1 vote

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

by
Answer:

Related questions