Card-testing patterns

aggregations

Card-testing patterns

Mastercard SQL Interview Question

Fraudsters often test a stolen card by making small payments at several different merchants on the same day. Mastercard's fraud team wants to catch that pattern early.

Find every card and day where the card was used at 3 or more different merchants. Show the card_id, the payment_date and the number of different merchants as merchant_count.

Asked of

  • Data Scientist
  • ML Engineer
  • Data Engineer
  • Data Analyst
  • AI Engineer

paymentsTable21 rows

Column NameType
payment_idBIGINT
merchant_idBIGINT
card_idBIGINT
amountDOUBLE
payment_dateDATE
is_fraudBOOLEAN

paymentsExample Input

payment_idmerchant_idcard_idamountpayment_dateis_fraud
8001190112.52024-07-01false
800229024992024-07-01false
8003490312024-07-01true
8004190312024-07-01true
8005590312024-07-01true
800639048602024-07-02false
80072905129.992024-07-02false
800849069.992024-07-02false
8009190723.42024-07-02false
80105908752024-07-03false

Example Output

card_idpayment_datemerchant_count
9032024-07-013

Explanation

On July 1, card 903 made three payments of 1.00, each at a different merchant: StreamPlus, QuickMart and FashionLane. That is exactly the pattern the fraud team is looking for, so it appears with a count of 3. No other card in the example was used at more than one merchant on the same day.

The example above is a small slice of the data. Your query runs against the full tables.