Modify the following SQL statement to only include States where you are owed money
SELECT state,SUM(baldue)
FROM Test
GROUP by state
ORDER BY state
Answer
Select state, SUM(baldue)
FROMTest
GROUP by state
HAVING sum(baldue) > 0
ORDER BY state
Here’s the rule. If a condition refers to an aggregate function, put that condition in the HAVING clause. Otherwise, use the WHERE clause. Here’s another rule: You can’t use HAVING unless you also use GROUP BY.
Where Vs Having gouravverma
