Consecutive Filing Users
Beginner Mode
Objective
Write a SQL query to find users who have filed taxes using any TurboTax product for 3 or more consecutive years. Output the qualifying user IDs in ascending order.
Table Schema:
- filed_taxes
| Column | Type | Description |
|---|---|---|
| user_id | INTEGER | Unique identifier for the user |
| filing_date | DATE | Date the tax return was filed |
| product | VARCHAR | TurboTax product used (e.g., 'TurboTax Basic', 'TurboTax Deluxe', 'TurboTax Premier', 'TurboTax Live') |
Task Requirements:
- A user may file multiple returns in the same year; each year should only count once
- The product used does not matter, any TurboTax product counts
- Consecutive means no gap years (e.g., 2019, 2020, 2021 is consecutive; 2019, 2021, 2022 is not)
- A user with multiple separate 3+ year streaks should only appear once in the output
- Order results by
user_idin ascending order
Output columns: user_id
Examples
Example 1:
Output:
Input:
| filed_taxes | ||
|---|---|---|
| filing_date | product | user_id |
| 2019-04-10 | TurboTax Basic | 1 |
| 2020-03-25 | TurboTax Deluxe | 1 |
| 2021-04-05 | TurboTax Basic | 1 |
| 2019-04-15 | TurboTax Premier | 2 |
| 2021-03-30 | TurboTax Basic | 2 |
| 2022-04-12 | TurboTax Deluxe | 2 |
| 2020-04-08 | TurboTax Live | 3 |
| 2021-04-14 | TurboTax Deluxe | 3 |
| 2022-03-20 | TurboTax Premier | 3 |
| 2023-04-01 | TurboTax Live | 3 |
| user_id |
|---|
| 1 |
| 3 |
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 →
Intuit