Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Querying Transactions in SQL
00:00
5 left

Querying Transactions in SQL

MediumSQL · PostgreSQL

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
Interviewer

Your question is Querying Transactions in SQL. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.