Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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
Window Functions for MoM Change
00:00
5 left

Window Functions for MoM Change

MediumSQL · PostgreSQL

Problem

Capital One's card analytics team wants to monitor monthly spending volume per cardholder across its credit card portfolio. Write a PostgreSQL query that calculates the month-over-month change in the average monthly transaction volume.

Assume transaction volume means the sum of posted purchase amounts for each cardholder during a calendar month. Include only cardholders with at least one qualifying transaction in that month. Exclude pending transactions, refunds, and transactions with a NULL amount.

Requirements

  1. Join cardholders, cards, and transactions to associate each transaction with its cardholder.
  2. Aggregate transaction volume first at the cardholder-month level.
  3. Calculate the average cardholder volume for each month.
  4. Use LAG to calculate the month-over-month percentage change, returning NULL for the first month.
  5. Round average volume and percentage change to two decimal places and order results chronologically.

Schema

cardholders
ColumnTypeDescription
cardholder_idPKINTEGERUnique cardholder identifier
cardholder_nameVARCHAR(100)Cardholder's full name
segmentVARCHAR(30)Customer portfolio segment
cards
ColumnTypeDescription
card_idPKINTEGERUnique card identifier
cardholder_idINTEGERReferences cardholders.cardholder_id
card_statusVARCHAR(20)Current card status
transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction identifier
card_idINTEGERReferences cards.card_id
transaction_tsTIMESTAMPTransaction timestamp
transaction_typeVARCHAR(20)Purchase or refund
statusVARCHAR(20)Transaction processing status
amountNUMERIC(12,2)Transaction amount in dollars
Tablescardholderscardstransactions
Interviewer

Your question is Window Functions for MoM Change. Start with the requirements and the three 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.