Conditional logic & CASE
Concept  ·  SQL & Querying

A CASE without ELSE yields NULL — which SUM ignores (usually what you want) and COUNT-of-CASE also ignores (which makes COUNT(CASE...) a conditional counter).

The missing ELSE is not an omission, it is a value: NULL. From there the aggregate decides everything — SUM and AVG skip it, COUNT(expr) skips it, COUNT(*) never looks. So COUNT(CASE WHEN paid THEN 1 END) counts payers; adding ELSE 0 breaks it, because zero is countable.

See it break
att
memberkind
Adaworkshop
Adadropin
Bendropin
The trap
SELECT
  member,
  COUNT(
    CASE
      WHEN kind = 'workshop' THEN 1
      ELSE 0
    END
  ) AS workshops
FROM
  att
GROUP BY
  member
ORDER BY
  member;
The fix
SELECT
  member,
  COUNT(
    CASE
      WHEN kind = 'workshop' THEN 1
    END
  ) AS workshops
FROM
  att
GROUP BY
  member
ORDER BY
  member;
INPUTYour queryThe fix
Ada21
Ben10

The workshop count included the drop-in rows too — a CASE with ELSE 0 makes every row countable, where dropping the ELSE leaves the non-matches NULL and COUNT skips them.

The rule

Omit ELSE for a conditional COUNT; use ELSE 0 only when zero is the meant contribution; or FILTER (WHERE ...) as the self-documenting spelling.

Shows up elsewhere
Conditional aggregationSUM over an empty / all-NULL group
Try one →Prove it in practice →