Question 1
Every row in the EMPLOYEES table has a non-null DEPT_ID, and the COMMISSION column is null for every employee who earns no commission. You must return one row for **each department id that appears in EMPLOYEES**, showing that id together with **the number of employees in that department whose COMMISSION is null**. A department in which every employee does have a commission must still appear in the result, reporting 0. Which query produces exactly that result?
A. SELECT dept_id, COUNT(commission) AS no_commission FROM employees GROUP BY dept_id
Inverts the requirement: COUNT(column) counts the rows where the column is NOT null, so this reports how many employees in each department DO have a commission — the complement of the number asked for.
B. SELECT dept_id, COUNT(CASE WHEN commission IS NULL THEN 1 ELSE 0 END) AS no_commission FROM employees GROUP BY dept_id
Represents the misconception that COUNT sums the CASE result. The ELSE 0 branch yields the non-null value 0, and COUNT counts every non-null argument, so this returns the total number of employees in each department regardless of commission. Only SUM(...) — not COUNT(...) — may safely use ELSE 0.
C. SELECT dept_id, COUNT(CASE WHEN commission IS NULL THEN 1 END) AS no_commission FROM employees GROUP BY dept_idCorrect answer
With no ELSE branch, the CASE expression evaluates to NULL for any employee who has a commission, and COUNT(expr) counts only non-null values, so exactly the null-commission employees are counted; a department with none produces 0 rather than NULL, because COUNT never returns null for a group that exists.
D. SELECT dept_id, COUNT(*) AS no_commission FROM employees WHERE commission = NULL GROUP BY dept_id
Represents the misconception that = NULL tests for nullness. Any comparison with NULL evaluates to UNKNOWN, never TRUE, so the WHERE clause admits no rows at all and the query returns an empty result set; IS NULL is the only test that works.
Explanation
COUNT(expr) tallies only the rows in the group for which expr is not null, so wrapping a CASE expression that deliberately returns NULL for the unwanted rows turns COUNT into a conditional counter. Adding an ELSE 0 branch defeats this, because 0 is a non-null value and is therefore counted like any other. Nullness itself must be tested with IS NULL, since an equality comparison against NULL yields UNKNOWN and filters every row away.