Break the problem into two parts: first, identify merchants with no succeeded subscription transactions in the last 180 days; second, among those, find merchants with recurring customers (at least two succeeded payments with same amount and card fingerprint, gaps 28-35 days) and compute the required metrics. Use CTEs and window functions to handle the logic cleanly and ensure each customer is counted once per merchant.
Pro tip: Clarify the definition of 'recurring payment behavior' and 'repeat transaction rate' upfront, and state your assumptions; this shows you think about ambiguity and business context, which is crucial for a data scientist at Stripe.
Identify merchants that have no succeeded Subscription transactions in the last 180 days by left joining or using NOT EXISTS on the transaction table filtered by transaction type and status.
For the remaining merchants, find customers with at least two succeeded payments in the last 180 days where the amount and card fingerprint match, and the gap between consecutive payments is between 28 and 35 days, using window functions like LAG to compare transactions.
Aggregate the recurring customers per merchant, ensuring each customer is counted only once per merchant, using DISTINCT or ROW_NUMBER to deduplicate.
Calculate the repeat transaction rate for the last 30 days as the number of customers with more than one transaction divided by total customers, or as specified, using conditional aggregation.
Combine the results to output merchant ID, recurring customer count, repeat transaction rate, first seen date (earliest transaction date for the merchant), and a flag indicating if the merchant currently uses subscriptions (based on the absence of subscription transactions in the last 180 days).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.