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 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.
| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| full_name | VARCHAR(100) | User full name |
| VARCHAR(150) | User email address | |
| account_status | VARCHAR(20) | Account status |
| Column | Type | Description |
|---|---|---|
| payment_method_idPK | INT | Unique payment method record |
| payment_token | VARCHAR(64) | Tokenized payment method identifier |
| method_type | VARCHAR(20) | Payment method type |
| is_active | BOOLEAN | Whether the payment method is active |
| Column | Type | Description |
|---|---|---|
| link_idPK | INT | Unique link record |
| user_id | INT | Linked user |
| payment_method_id | INT | Linked payment method |
| linked_at | DATE | Date the link was created |