Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sales by Payment Method: Total and Unique Customers

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

Your question is Sales by Payment Method: Total and Unique Customers. 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

Meta commerce analytics needs a payment-method summary for successful transactions processed across Meta Pay and related checkout methods. Write a PostgreSQL query that joins payment transactions to the payment-method dimension and produces one row per payment method.

Requirements

  1. Include every payment method, including methods with no successful transactions.
  2. Calculate total sales value from transactions where status = 'completed'.
  3. Count unique non-null paying customers with COUNT(DISTINCT ...).
  4. Sort by total sales value descending, then payment method name ascending for deterministic tie handling.

Schema

payment_methods
ColumnTypeDescription
method_idPKINTUnique payment method identifier
method_nameVARCHAR(50)Payment method display name
payments
ColumnTypeDescription
payment_idPKINTUnique payment transaction identifier
customer_idINTCustomer identifier, nullable for anonymous transactions
method_idINTReferenced payment method identifier
amountNUMERIC(10,2)Transaction amount
statusVARCHAR(20)Payment processing status
Tablespayment_methodspayments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results