• edited by
18,054 views
56 56 votes

The employee information in a company is stored in the relation

  • Employee (name, sex, salary, deptName)

Consider the following SQL query

Select deptName
    From Employee
    Where sex = ‘M’
    Group by deptName
    Having avg(salary) >
        (select avg (salary) from Employee)

It returns the names of the department in which

  1. the average salary is more than the average salary in the company

  2. the average salary of male employees is more than the average salary of all male employees in the company

  3. the average salary of male employees is more than the average salary of employees in same the department

  4. the average salary of male employees is more than the average salary in the company

4 Answers

Best answer
48 48 votes
D is the answer.

The inner query is over all department and over both male and female employees while the outer query is only for male employees.
• selected by
5 5 votes
In outer query :the average salary of male employees in each department

inner query:  the average salary in the company

ans d
4 4 votes
A) the names of the department in which the average salary is more than the average salary in the company

select deptName

          from Employee

          Group by deptName

          Having avg(salary) > ( select avg(salary) from Employee )

B)the names of the department in which the average salary of male employees is more than the average salary of all male employees in the company

select deptName

      from Employee

      where sex=’M’

      Group by deptName

      Having avg (salary) > ( select avg(salary) from Employee where SEX=”M” )

C)the names of the department in which  the average salary of male employees is more than the average salary of employees in same the department

select deptName

         from Employee  e

         where sex=”M”

        Group by deptName

         Having avg(salary) > ( select avg(salary) from Employee ee where ee.deptName = e.deptName )

 

  D)the names of the department in which the average salary of male employees is more than the average salary in the company

same as querry provided in question.
Answer:
Position:
Show:

Related questions

39 39 votes
4 answers 4 answers
17.8k
17.8k views
Kathleen asked Sep 18, 2014
17,781 views
The order of an internal node in a $B+$ tree index is the maximum number of children it can have. Suppose that a child pointer takes $6$ bytes, the search field value tak...
93 93 votes
9 answers 9 answers
28.9k
28.9k views
Kathleen asked Sep 18, 2014
28,882 views
Consider the relation Student (name, sex, marks), where the primary key is shown underlined, pertaining to students in a class that has at least one boy and one girl. Wha...
66 66 votes
8 answers 8 answers
30.3k
30.3k views
Kathleen asked Sep 18, 2014
30,295 views
The relation scheme $\text{Student Performance (name, courseNo, rollNo, grade)}$ has the following functional dependencies:name, courseNo, $\rightarrow$ graderollNo, cour...
92 92 votes
13 answers 13 answers
34.7k
34.7k views
go_editor asked Apr 24, 2016
34,742 views
Consider three IP networks $A, B$ and $C$. Host $H_A$ in network $A$ sends messages each containing $180$ $bytes$ of application data to a host $H_C$ in network $C$. The ...