Consecutive Filing Users
Intuit 🧠 Hard SQL
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_id in ascending order

Output columns: user_id

Examples

Example 1:

Input:

filed_taxes
filing_dateproductuser_id
2019-04-10TurboTax Basic1
2020-03-25TurboTax Deluxe1
2021-04-05TurboTax Basic1
2019-04-15TurboTax Premier2
2021-03-30TurboTax Basic2
2022-04-12TurboTax Deluxe2
2020-04-08TurboTax Live3
2021-04-14TurboTax Deluxe3
2022-03-20TurboTax Premier3
2023-04-01TurboTax Live3

Output:
user_id
1
3
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →