Identify Recurring Subscription Charges From Card Transactions in SQL

Last updated: November 29, 2026

Quick Overview

Using a card_transactions table, write a query that finds each customer and merchant pair with at least three posted charges at a monthly cadence (26 to 35 days apart) and stable amounts (within 10% of the previous charge), and predicts the next expected charge date.

JPMorgan Chase
Data Manipulation (SQL/Python)
Data Scientist
JPMorgan Chase
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Using a card_transactions table, write a query that finds each customer and merchant pair with at least three posted charges at a monthly cadence (26 to 35 days apart) and stable amounts (within 10% of the previous charge), and predicts the next expected charge date.

The Chase mobile app surfaces recurring payments so customers can spot and manage subscriptions, and similar logic feeds spend insights and attrition models. The interviewer checks window function fluency (LAG over a partition), turning a fuzzy business definition into precise filters, and sanity-checking the output.

What the Interviewer Expects
  • Filters to posted debit charges before windowing
  • Uses LAG partitioned by customer and merchant to compute gaps and amount changes
  • Aggregates per pair with HAVING on count, gap range and price stability
  • Predicts next date from the average gap
  • Names edge cases like price increases, annual plans and pending duplicates
Key Topics to Cover
window functions
LAG
date arithmetic
HAVING
recurring payments
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you also catch annual and weekly subscriptions?
  • Merchant names vary (NETFLIX.COM, NETFLIX 866). How do you normalize them?
  • How would you flag a subscription the customer likely forgot about?
  • How would you rewrite the date arithmetic for Postgres or Snowflake?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Assume card_transactions(customer_id, merchant_id, txn_date, amount, status) with one row per charge, positive amount for purchases, and status in POSTED or PENDING. Pending rows can be duplicated...

Approach
  1. CTE charges: posted purchases with LAG(txn_date) and LAG(amount) per customer and merchant.
  2. CTE gaps: day gap and relative amount change for every charge after the first.
  3. Aggregate pe...

Submit Your Answer
Markdown supported

Related Questions