Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Query Code Test and Bug Fix

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

Your question is SQL Query Code Test and Bug Fix. Start with the requirements and the two tables 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

Tell me about a time you worked on a SQL query code test and then fixed a bug in the solution.

For the SQL portion, use the provided customers and payments tables. Write the corrected query that returns settled payment totals for active customers, including customers with no settled payments.

Output

  1. One row per active customer, with customer_name and total_settled_amount.
  2. Include customers with no settled payments as zero.
  3. Sort by total descending, then customer name ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
is_activeBOOLEANWhether the customer is active
payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
customer_idINTCustomer associated with the payment
amountNUMERIC(12,2)Payment amount
statusVARCHAR(40)Payment processing status
Tablescustomerspayments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results