Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Querying Transactions in SQL

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

Your question is Querying Transactions in SQL. 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

Business Context

Shopify Financial Operations needs a monthly view of Shopify Payments activity by merchant for Q1 2025. The report should distinguish settled sales from settled refunds and exclude failed or pending transactions.

Task

Write a PostgreSQL query that joins payment_transactions to shopify_merchants and returns one row per merchant and transaction month.

Requirements

  1. Include only transactions processed from January 1 through March 31, 2025 with status = 'settled'.
  2. Calculate settled sale count, settled transaction count, gross sales, refund amount, net sales, and refund rate as a percentage of gross sales.
  3. Include merchant name and plan, and sort by transaction month followed by merchant name.
  4. Return a NULL refund rate when gross sales are zero.

Schema

shopify_merchants
ColumnTypeDescription
merchant_idPKINTUnique Shopify merchant identifier
merchant_nameVARCHAR(100)Merchant display name
planVARCHAR(30)Shopify subscription plan
payment_transactions
ColumnTypeDescription
transaction_idPKINTUnique payment transaction identifier
merchant_idINTMerchant associated with the transaction
order_idVARCHAR(30)Shopify order reference
transaction_typeVARCHAR(20)Payment transaction type
statusVARCHAR(20)Transaction processing status
amountDECIMAL(12,2)Transaction amount in the reporting currency
processed_atDATEDate the transaction was processed
Tablespayment_transactionsshopify_merchants
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results