User Transaction Milestone
Beginner Mode
Objective
Write a SQL query to find the third transaction for each user from the transactions table.
Table Schema:
transactions
| Column | Type | Description |
|---|---|---|
| transaction_id | INTEGER | Unique identifier for each transaction |
| user_id | INTEGER | ID of the user who made the transaction |
| spend | DECIMAL | Amount spent in the transaction |
| transaction_date | DATE | Date when the transaction occurred |
| product_id | INTEGER | ID of the product purchased |
Task Requirements:
- Identify the third transaction for each user based on transaction_date
- Return only users who have at least 3 transactions
- Display user_id, spend, and transaction_date for the third transaction
Output columns: user_id, spend, transaction_date
Examples
Example 1:
Output:
Input:
| transactions | ||||
|---|---|---|---|---|
| product_id | spend | transaction_date | transaction_id | user_id |
| 501 | 25.5 | 2024-01-10 | 1 | 101 |
| 502 | 42 | 2024-01-15 | 2 | 101 |
| 503 | 18.75 | 2024-01-20 | 3 | 101 |
| 504 | 33 | 2024-01-12 | 4 | 102 |
| 505 | 55.25 | 2024-01-18 | 5 | 102 |
| spend | transaction_date | user_id |
|---|---|---|
| 18.75 | 2024-01-20 | 101 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Uber