Your question is Bucket QuickBooks Customers by Payment Behavior. Start with the requirements and the one table on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
You are given a quickbooks_payments table with one row per invoice payment attempt. Write a SQL query that buckets each customer by payment behavior using a CASE WHEN statement, then returns the number of payment records in each bucket. Treat payments made on or before the due date as On Time, payments made after the due date as Late, and rows with no payment date as Unpaid. Return the bucket name and the count of records in each bucket, ordered by record count descending and then bucket name.
| Column | Type | Description |
|---|---|---|
| payment_idPK | INT | Unique payment record ID |
| customer_name | VARCHAR(100) | Customer name in QuickBooks |
| invoice_date | DATE | Date the invoice was created |
| due_date | DATE | Date the invoice payment was due |
| payment_date | DATE | Date payment was received; NULL if unpaid |
| amount | DECIMAL(10,2) | Invoice amount |