COUNT with IS NULL filter
Weekly retail scorecard for the morning huddle. How many accounts are currently open? `retail_accounts` has a `close_date` that's NULL for any account still on the books. Single number, call the column `open_accounts`.
| Column | Type | Key |
|---|---|---|
| account_id | INT | PK |
| customer_id | INT | FK → retail_customers |
| product_id | INT | FK → retail_products |
| branch_id | INT | FK → retail_branches |
| open_date | TEXT | |
| close_date | TEXT | |
| status | TEXT | |
| ownership_type | TEXT | |
| interest_rate | REAL | |
| original_balance | REAL | |
| credit_limit | REAL | |
| fico_at_orig | INT | |
| maturity_date | TEXT |
Each hint you reveal reduces the XP you can earn. Try the query first.
Accounts still on the books have a specific data pattern in the close column. How does SQL test for the absence of a value — and why can't you use = for this?
Count rows from retail_accounts where close_date is absent — alias the column open_accounts so the scorecard cell binds correctly.
You could also check `status = 'Open'` — in this seed the two are consistent, but `close_date IS NULL` is the more defensive query because it doesn't depend on status being kept up to date.