Table Emp(id, dept, salary) has rows (1,’HR’,3000), (2,’IT’,5000), (3,’IT’,4000), (4,’Ops’,2000). SELECT dept FROM Emp GROUP BY dept HAVING MAX(salary) – MIN(salary) > 0; What is returned?
Correct answer D. IT
Explanation
HAVING may use any aggregate expression evaluated per group. HR and Ops each have one employee, so MAX and MIN are equal and the difference is 0, which fails the test. IT has 5000 and 4000, a difference of 1000, so only IT is returned. In effect, the query lists departments whose salaries are not all the same.
Answer checked How we write and check questions
Discussion