Bird
0
0

Given the table Employees with column Department containing values: 'Sales', NULL, 'HR', NULL, 'Sales', what will be the result of:

medium📝 query result Q4 of 15
SQL - GROUP BY and HAVING
Given the table Employees with column Department containing values: 'Sales', NULL, 'HR', NULL, 'Sales', what will be the result of:
SELECT Department, COUNT(*) FROM Employees GROUP BY Department;?
A[{'Sales', 2}, {'HR', 1}, {NULL, 0}]
B[{'Sales', 2}, {'HR', 1}]
C[{'Sales', 2}, {'HR', 1}, {NULL, 1}, {NULL, 1}]
D[{'Sales', 2}, {'HR', 1}, {NULL, 2}]
Step-by-Step Solution
Solution:
  1. Step 1: Identify groups formed by Department values

    Departments are 'Sales', 'HR', and NULL. NULL values form one group.
  2. Step 2: Count rows per group

    'Sales' appears twice, 'HR' once, NULL twice.
  3. Final Answer:

    [{'Sales', 2}, {'HR', 1}, {NULL, 2}] -> Option D
  4. Quick Check:

    NULLs grouped together with count 2 [OK]
Quick Trick: NULLs count as one group with all NULL rows [OK]
Common Mistakes:
MISTAKES
  • Splitting NULLs into multiple groups
  • Ignoring NULL group in result
  • Counting NULL group as zero

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes