Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Flag Suspicious Lyft Trip Cards

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Flag Suspicious Lyft Trip Cards. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

You are given Lyft trip transaction data and need to identify payment cards showing patterns that may indicate fraud. Write a SQL query that returns cards with suspicious activity in the last 7 days based on trip behavior and payment outcomes. A card should be flagged if it has at least 3 declined attempts, or if it has trips in at least 3 distinct cities, or if its total approved spend exceeds 500 in that 7-day window. Return the card, rider, counts of approved and declined trips, distinct city count, approved spend, and a fraud flag reason.

Schema

trip_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
trip_idINTTrip associated with the payment event
rider_idINTRider who initiated the trip
card_idINTPayment card used for the trip
transaction_tsTIMESTAMPTransaction timestamp
amount_usdNUMERIC(10,2)Transaction amount in USD
payment_statusVARCHAR(20)Payment outcome such as approved, declined, or pending
riders
ColumnTypeDescription
rider_idPKINTUnique rider identifier
rider_nameVARCHAR(100)Rider full name
home_cityVARCHAR(50)Rider home city
trips
ColumnTypeDescription
trip_idPKINTUnique trip identifier
cityVARCHAR(50)City where the trip occurred
ride_typeVARCHAR(30)Lyft ride type
requested_atTIMESTAMPTrip request timestamp
Tablestrip_transactionsriderstrips
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results