# GATE | GATE-CS-2004 | Question 53

• Last Updated : 28 Jun, 2021

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
(A) the average salary is more than the average salary in the company
(B) the average salary of male employees is more than the average salary of all male employees in the company
(C) the average salary of male employees is more than the average salary of employees in the same department

(D) the average salary of male employees is more than the average salary in the company

Explanation: In this SQL query, we have

```select deptName ---------------  Select the department name
from Employee  ----------------  From the database of employees
where sex = 'M' ---------------  Where sex is male (M)
group by deptName -------------  Group by the name of the department
having avg (salary) >
(select avg (salary) from Employee)  -----  Having the average salary
greater than the average salary
of all employees in the organization.
```

So, this query would return the name of all departments in which the average salary of male employees is greater than the average salary of all employees in the company.

Hence, D is the correct choice.

Please comment below if you find anything wrong in the above post.

Quiz of this Question

My Personal Notes arrow_drop_up