edited by
11,975 views
38 votes
38 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

edited by

3 Answers

Best answer
30 votes
30 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
4 votes
4 votes
In outer query :the average salary of male employees in each department

inner query:  the average salary in the company

ans d
2 votes
2 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:

Related questions

11.5k
views
2 answers
27 votes
Kathleen asked Sep 18, 2014
11,504 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...
18.2k
views
7 answers
65 votes
Kathleen asked Sep 18, 2014
18,208 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...
18.8k
views
5 answers
45 votes
Kathleen asked Sep 18, 2014
18,822 views
The relation scheme $\text{Student Performance (name, courseNo, rollNo, grade)}$ has the following functional dependencies:name, courseNo, $\rightarrow$ graderollNo, cour...
29.8k
views
7 answers
64 votes
Kathleen asked Sep 18, 2014
29,803 views
Consider the following relation schema pertaining to a students database:Students (rollno, name, address)Enroll (rollno, courseno, coursename)where the primary keys are s...