The employee information in a company is stored in the relation Employee…
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
- E.
Question not attempted
Attempted by 812 students.
Show answer & explanation
Correct answer: D
The SQL query selects department names from the Employee table where the sex is 'M' (male), groups the results by department, and filters departments where the average salary of male employees is greater than the average salary of all employees in the company. The subquery (select avg(salary) from Employee) calculates the overall average salary across all employees. The HAVING clause compares the average salary of male employees in each department to this company-wide average. Therefore, the query returns departments where the average salary of male employees exceeds the average salary of the entire company.