Write SQL for seller and category metrics
Company: Meta
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
Assume the following marketplace tables.
Table: `listing_interactions`
- `buyer_id` STRING
- `seller_id` STRING
- `product_id` STRING
- `interaction_date` DATE
- `listing_interactions` INT — number of buyer-seller interactions for that product on that date
Table: `dim_all_products`
- `product_id` STRING
- `category` STRING
- `snapshot_date` DATE
- `create_date` DATE
- `country` STRING
Assumptions:
- `listing_interactions.product_id` joins to `dim_all_products.product_id`.
- Each `product_id` in `dim_all_products` represents one listing/product.
- Use all available interaction history unless a question specifies a time filter.
- All dates are in UTC.
- A product has "multiple interactions" if its total `listing_interactions`, summed across all rows, is greater than 1.
- "Created in the last 7 days" means `create_date` is between `current_date - 6 days` and `current_date`, inclusive.
Write SQL to answer both questions below:
1. How many sellers have more than 3 distinct products that each have multiple interactions?
- Required output: one row with column `sellers_with_gt_3_multi_interaction_products`.
2. Among listings in the US that were created in the last 7 days, what percentage of total listing interactions comes from the `vehicle` category?
- Required output: one row with column `vehicle_interaction_pct`.
- Define this as:
`sum(listing_interactions for US listings created in the last 7 days where category = 'vehicle') / sum(listing_interactions for all US listings created in the last 7 days)`.
- Handle divide-by-zero safely if there are no qualifying interactions.
Quick Answer: This question evaluates proficiency in SQL data manipulation—principally joins, aggregations, grouping, filtering, date arithmetic, and safe handling of division—and targets the Data Manipulation (SQL/Python) domain for a Data Scientist role; level of abstraction: practical application.