Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Shared Payment Methods

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Detect Shared Payment Methods. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

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

Problem

You are given Lyft-style account and payment data and need to identify users who share the same payment method with other accounts. Write a SQL query that returns each shared payment method along with the users linked to it, but only for active payment methods and non-deactivated accounts. The result should include the payment method token, the number of distinct linked users, and the user details for those flagged payment methods.

Schema

lyft_users
ColumnTypeDescription
user_idPKINTUnique user identifier
full_nameVARCHAR(100)User full name
emailVARCHAR(150)User email address
account_statusVARCHAR(20)Account status
payment_methods
ColumnTypeDescription
payment_method_idPKINTUnique payment method record
payment_tokenVARCHAR(64)Tokenized payment method identifier
method_typeVARCHAR(20)Payment method type
is_activeBOOLEANWhether the payment method is active
user_payment_methods
ColumnTypeDescription
link_idPKINTUnique link record
user_idINTLinked user
payment_method_idINTLinked payment method
linked_atDATEDate the link was created
Tableslyft_userspayment_methodsuser_payment_methods
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results