Total Successful Payments
payments stores payment attempts. status is succeeded, failed or refunded.
For each customer with at least one succeeded payment, sum the amounts of their succeeded payments, rounded with ROUND(x, 2).
Return columns customer_id, total_paid. Order by total_paid descending, then customer_id ascending.
Schema
CREATE TABLE payments ( payment_id INTEGER PRIMARY KEY, customer_id INTEGER NOT NULL, amount REAL NOT NULL, status TEXT NOT NULL, paid_at TEXT NOT NULL );
Sample data
payments
| payment_id | customer_id | amount | status | paid_at |
|---|---|---|---|---|
| 1 | 7 | 120 | succeeded | 2026-02-01 |
| 2 | 7 | 80 | failed | 2026-02-02 |
| 3 | 8 | 45.5 | succeeded | 2026-02-02 |
| 4 | 9 | 300 | refunded | 2026-02-03 |
| 5 | 8 | 54.5 | succeeded | 2026-02-05 |
| 6 | 10 | 19.99 | succeeded | 2026-02-06 |
| 7 | 7 | 30 | succeeded | 2026-02-07 |
Hint 1
Filter with WHERE status = 'succeeded' first; customers with no successes then drop out on their own.
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.