Compute unique visitors by department
Company: Amazon
Role: Software Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: Medium
Interview Round: Technical Screen
You have two tables: products(product_id, department, category, subcategory) where department > category > subcategory form a parent–child hierarchy, and click_log(user_id, product_id, event_time). For any given department name as input, write SQL to return the number of distinct users who clicked products in that department over a specified time range. Ensure that a user who clicks multiple products within the same department is counted once, and extend your query to return counts for all departments in one result.
Quick Answer: This question evaluates proficiency in SQL data manipulation, specifically JOIN operations between event and product tables, deduplicating distinct users, applying time-range filters, and reasoning about hierarchical product attributes (department/category/subcategory).