Bird
0
0

You wrote this query:

medium📝 Debug Q6 of 15
SQL - GROUP BY and HAVING
You wrote this query:
SELECT Department, COUNT(*) FROM Employees GROUP BY Department HAVING Department IS NOT NULL;
but it returns no rows for NULL departments. How can you fix it to include NULL group counts?
ARemove the HAVING clause to include NULL groups.
BChange HAVING to WHERE Department IS NOT NULL.
CAdd GROUP BY COALESCE(Department, 'Unknown').
DUse HAVING Department IS NULL instead.
Step-by-Step Solution
Solution:
  1. Step 1: Understand HAVING clause effect

    HAVING Department IS NOT NULL filters out NULL groups after grouping.
  2. Step 2: Fix query to include NULL groups

    Removing HAVING clause keeps all groups including NULL.
  3. Final Answer:

    Remove the HAVING clause to include NULL groups. -> Option A
  4. Quick Check:

    HAVING filters groups; remove to keep NULL [OK]
Quick Trick: HAVING filters groups; remove to keep NULL groups [OK]
Common Mistakes:
MISTAKES
  • Replacing HAVING with WHERE (wrong place)
  • Forgetting HAVING filters after grouping
  • Using HAVING IS NULL instead of IS NOT NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes