Practice mode DBMS and SQL

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.