Merchants with high fraud rates

aggregations

Merchants with high fraud rates

Mastercard SQL Interview Question

Mastercard's fraud team reviews merchants where a large share of card payments turn out to be fraudulent.

Find every merchant where more than 30% of payments were fraudulent. Show the merchant_name, the number of payments as total_payments and the number of fraudulent payments as fraud_payments.

Asked of

  • Data Analyst
  • Data Scientist
  • ML Engineer
  • Analytics Engineer

paymentsTable21 rows

Column NameType
payment_idBIGINT
merchant_idBIGINT
card_idBIGINT
amountDOUBLE
payment_dateDATE
is_fraudBOOLEAN

merchantsTable5 rows

Column NameType
merchant_idBIGINT
merchant_nameVARCHAR
categoryVARCHAR
countryVARCHAR

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

merchantsExample Input

merchant_idmerchant_namecategorycountry
1QuickMartConvenienceUnited States
2GadgetHubElectronicsUnited States
3SkyFly TravelTravelUnited Kingdom
4StreamPlusDigital ServicesUnited States
5FashionLaneApparelGermany

Example Output

merchant_nametotal_paymentsfraud_payments
FashionLane21
QuickMart31
StreamPlus21

Explanation

QuickMart took 3 payments in the example, and 1 of them was fraudulent, which is 33%, so it qualifies. StreamPlus and FashionLane each had 1 fraudulent payment out of 2. GadgetHub had no fraudulent payments, so it is left out.

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