56 56 votes The employee information in a company is stored in the relationEmployee (name, sex, salary, deptName)Consider the following SQL querySelect 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 whichthe average salary is more than the average salary in the companythe average salary of male employees is more than the average salary of all male employees in the companythe average salary of male employees is more than the average salary of employees in same the departmentthe average salary of male employees is more than the average salary in the company Databases gatecse-2004 databases sql normal + – Kathleen 18.1k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments mrinmoyh commented Jul 18, 2019 reply Follow flag Gurdeep Saini Can we have HAVING salary instead of HAVING avg(salary) here??? 0 0 replyShare gouravs785 commented Oct 3, 2019 reply Follow flag "Any attribute that is present in the having clause without being aggregated must appear in the group by clause, otherwise the query is treated as erroneous." Korth 6th edition chapter 3 , page 88. 2 2 replyShare Deepak Poonia commented Jul 22, 2024 i edited by Deepak Poonia Aug 6, 2024 reply Follow flag Detailed Video Solution: https://youtu.be/zb6vXpZVo1E?t=3553&feature=shared 0 0 replyShare Please log in or register to add a comment.
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. Arjun answered May 3, 2015 • selected May 19, 2015 by Rajarshi Sarkar Arjun comment Share Follow See all 12 Comments 12 12 Comments reply Show 9 previous comments Cristine commented Dec 10, 2018 reply Follow flag I am not getting how group by clause has no significance here? 2 2 replyShare Gurdeep Saini commented Dec 29, 2018 reply Follow flag @Cristina6884 here group by grouping all male according to department so the avg we calculated is the avg of male salary in that department 0 0 replyShare kp1 commented Dec 6, 2019 reply Follow flag Here group by clause is used to support having clause... 0 0 replyShare Please log in or register to add a comment.
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 amkrj answered May 9, 2015 amkrj comment Share Follow See all 3 Comments 3 3 Comments reply Shadan Karim commented Oct 5, 2018 reply Follow flag Answer should be Department names in which Avg Salary of male employees in that department is greater than Avg salary of all employees in the table 0 0 replyShare manav kothari commented Oct 7, 2018 reply Follow flag In outer query :the average salary of male employees in each department inner query: the average salary in the company options d does not specify in each department so i think answer d also wrong 1 1 replyShare shethnisarg commented May 9, 2020 reply Follow flag "The names of the department in which" is already mentioned in the question.. 0 0 replyShare Please log in or register to add a comment.
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. Shamshuddin answered Sep 8, 2022 Shamshuddin comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes 2 akshay_123 answered Aug 23, 2025 akshay_123 comment Share Follow 0 reply Please log in or register to add a comment.