QuickBooks vs. TurboTax: Count Tax Filings by Product Line
Quick Overview
Write a SQL query that joins tax filings to a product table and counts the filings on two product lines, ignoring filing status and every other line. It tests joining a fact table to a lookup table, grouping at the right level, and counting filings instead of filers.
QuickBooks vs. TurboTax: Count Tax Filings by Product Line
Company: Intuit
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Count the tax filings made with `'TurboTax'` products and with `'QuickBooks'` products. Filings on other product lines are excluded, and every filing counts regardless of its `filing_status`. Return `product_line` and `total_filings`, ordered alphabetically by `product_line`.
```hint Products and product lines
One product line can contain several products. Check which column your grouping uses.
```
### Input Table(s)
`products` has primary key `product_id`.
| Column | Type | Meaning |
|---|---|---|
| product_id | INT | Primary key |
| product_name | VARCHAR(100) | Name of the specific product. NOT NULL |
| product_line | VARCHAR(50) | The product line the product belongs to, such as `'TurboTax'` or `'QuickBooks'`. NOT NULL |
`tax_filings` has primary key `filing_id`, and `product_id` references `products.product_id`.
| Column | Type | Meaning |
|---|---|---|
| filing_id | INT | Primary key. One row per filing |
| user_id | INT | The user who filed. NOT NULL |
| product_id | INT | The product used for the filing. NOT NULL |
| filing_date | DATE | The date of the filing. NOT NULL |
| filing_status | VARCHAR(20) | The status of the filing. NOT NULL; it does not affect the count |
### Output Contract
- Columns, in this order: `product_line`, `total_filings`.
- At most two rows: one for `'TurboTax'` and one for `'QuickBooks'`. A line appears only when it has at least one filing.
- `total_filings` is the number of `tax_filings` rows for that line. A user who files three times adds 3.
- Order by `product_line` ascending. Each line appears once, so `'QuickBooks'` comes before `'TurboTax'` and the order is fully determined.
### Example
Input table `products`:
| product_id | product_name | product_line |
|---|---|---|
| 1 | TurboTax Deluxe | TurboTax |
| 2 | TurboTax Premier | TurboTax |
| 3 | QuickBooks Online | QuickBooks |
| 4 | Budget Planner | Budgeting |
Input table `tax_filings`:
| filing_id | user_id | product_id | filing_date | filing_status |
|---|---|---|---|---|
| 101 | 1 | 1 | 2024-03-01 | accepted |
| 102 | 2 | 2 | 2024-03-05 | rejected |
| 103 | 1 | 2 | 2024-04-10 | pending |
| 104 | 3 | 3 | 2024-01-31 | accepted |
| 105 | 4 | 4 | 2024-02-15 | accepted |
| 106 | 2 | 3 | 2024-04-15 | accepted |
Expected output:
| product_line | total_filings |
|---|---|
| QuickBooks | 2 |
| TurboTax | 3 |
Products 1 and 2 are both on the TurboTax line, so filings 101, 102 and 103 count toward TurboTax. Filing 102 is rejected and still counts, and user 1 filed twice on this line, which adds 2. Filings 104 and 106 use product 3 and count toward QuickBooks. Filing 105 is on the Budgeting line and is excluded.
### Constraints and Clarifications
- `products` has at most 100 rows and `tax_filings` has at most 10,000 rows.
- `product_line` values include `'TurboTax'`, `'QuickBooks'` and possibly other lines. Match the two values exactly as written.
- Each `filing_id` is unique, and every `tax_filings.product_id` references a valid row in `products`.
- No column in either table is NULL.
- Every filing counts whatever its `filing_status`, including rejected and pending ones.
- A product line with no filings does not appear in the output. There is no row with a count of 0.
Overview: Write a SQL query that joins tax filings to a product table and counts the filings on two product lines, ignoring filing status and every other line. It tests joining a fact table to a lookup table, grouping at the right level, and counting filings instead of filers.
Count the tax filings made with 'TurboTax' products and with 'QuickBooks' products. Filings on other product lines are excluded, and every filing counts regardless of its filing_status. Return product_line and total_filings, ordered alphabetically by product_line.
Input Table(s)
products has primary key product_id.
Column
Type
Meaning
product_id
INT
Primary key
product_name
VARCHAR(100)
Name of the specific product. NOT NULL
product_line
VARCHAR(50)
The product line the product belongs to, such as 'TurboTax' or 'QuickBooks'. NOT NULL
tax_filings has primary key filing_id, and product_id references products.product_id.
Column
Type
Meaning
filing_id
INT
Primary key. One row per filing
user_id
INT
The user who filed. NOT NULL
product_id
INT
The product used for the filing. NOT NULL
filing_date
DATE
The date of the filing. NOT NULL
filing_status
VARCHAR(20)
The status of the filing. NOT NULL; it does not affect the count
Output Contract
Columns, in this order:
product_line
,
total_filings
.
At most two rows: one for
'TurboTax'
and one for
'QuickBooks'
. A line appears only when it has at least one filing.
total_filings
is the number of
tax_filings
rows for that line. A user who files three times adds 3.
Order by
product_line
ascending. Each line appears once, so
'QuickBooks'
comes before
'TurboTax'
and the order is fully determined.
Example
Input table products:
product_id
product_name
product_line
1
TurboTax Deluxe
TurboTax
2
TurboTax Premier
TurboTax
3
QuickBooks Online
QuickBooks
4
Budget Planner
Budgeting
Input table tax_filings:
filing_id
user_id
product_id
filing_date
filing_status
101
1
1
2024-03-01
accepted
102
2
2
2024-03-05
rejected
103
1
2
2024-04-10
pending
104
3
3
2024-01-31
accepted
105
4
4
2024-02-15
accepted
106
2
3
2024-04-15
accepted
Expected output:
product_line
total_filings
QuickBooks
2
TurboTax
3
Products 1 and 2 are both on the TurboTax line, so filings 101, 102 and 103 count toward TurboTax. Filing 102 is rejected and still counts, and user 1 filed twice on this line, which adds 2. Filings 104 and 106 use product 3 and count toward QuickBooks. Filing 105 is on the Budgeting line and is excluded.
Constraints and Clarifications
products
has at most 100 rows and
tax_filings
has at most 10,000 rows.
product_line
values include
'TurboTax'
,
'QuickBooks'
and possibly other lines. Match the two values exactly as written.
Each
filing_id
is unique, and every
tax_filings.product_id
references a valid row in
products
.
No column in either table is NULL.
Every filing counts whatever its
filing_status
, including rejected and pending ones.
A product line with no filings does not appear in the output. There is no row with a count of 0.