Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Bucket QuickBooks Customers by Payment Behavior

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

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 need to log in / sign up to run or submit.

Problem

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.

Schema

quickbooks_payments
ColumnTypeDescription
payment_idPKINTUnique payment record ID
customer_nameVARCHAR(100)Customer name in QuickBooks
invoice_dateDATEDate the invoice was created
due_dateDATEDate the invoice payment was due
payment_dateDATEDate payment was received; NULL if unpaid
amountDECIMAL(10,2)Invoice amount
Tablesquickbooks_payments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results