1-- subscriptions table: opted_in column is nullable
2-- NULL means "not set", TRUE means opted in, FALSE means opted out
3SELECT
4 COUNT(*) AS total_users,
5 COUNT(opted_in) AS opted_in_count,
6 COUNT(*) - COUNT(opted_in) AS unknown_count
7FROM subscriptions;
8-- opted_in_count should only count TRUE rows, not all non-NULL rows
no lines flagged
#022PracticeEasy10 min · 50 XP
COUNT Ignores NULL Values
A query counting opt-in users returns an inflated number. Find the line with the wrong aggregate.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.