Account Balance Tiers
A digital wallet labels each account by its current balance:
- NULL balance: unknown
- below 0: overdrawn
- 0 up to (but not including) 1000: standard
- 1000 or more: premium
Return columns account_id, tier. Row order does not matter.
Schema
CREATE TABLE accounts ( account_id INTEGER PRIMARY KEY, holder TEXT NOT NULL, balance REAL );
Sample data
accounts
| account_id | holder | balance |
|---|---|---|
| 1 | Layla | 2500 |
| 2 | Marco | -40.25 |
| 3 | Nadia | 999.99 |
| 4 | Oscar | NULL |
| 5 | Pooja | 0 |
| 6 | Rami | 1000 |
Hint 1
CASE checks its WHEN branches top to bottom and stops at the first match.
Hint 2
Put the NULL check first. A NULL balance fails every comparison and would otherwise fall through to ELSE.
Good practice for: Data Analyst, Backend Developer, Business Analyst
SQL (SQLite)
Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.