Compute unique visitors per department from clicks

Quick Overview

This question evaluates a candidate's skill in data manipulation and deduplication using SQL/Python, specifically mapping hierarchical product metadata to departments and computing unique user counts without double-counting, and is categorized under Data Manipulation (SQL/Python).

Compute unique visitors per department from clicks

Company: Amazon

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

Given tables Products(product_id, department, category, subcategory) where department > category > subcategory form a hierarchy, and ClickLog(user_id, product_id, event_ts) that records user clicks, write SQL to compute the number of unique customers who visited (clicked any product in) a specified department over a given time range. Ensure correct mapping from product_id to its department and avoid double-counting users who clicked multiple products/categories within the same department. Explain your indexing/partitioning strategy for large-scale data and how you would extend the query to return results for all departments.

Quick Answer: This question evaluates a candidate's skill in data manipulation and deduplication using SQL/Python, specifically mapping hierarchical product metadata to departments and computing unique user counts without double-counting, and is categorized under Data Manipulation (SQL/Python).

|Home/Data Manipulation (SQL/Python)/Amazon
Amazon logo
Amazon
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenData Manipulation (SQL/Python)
6
0

Given tables Products(product_id, department, category, subcategory) where department > category > subcategory form a hierarchy, and ClickLog(user_id, product_id, event_ts) that records user clicks, write SQL to compute the number of unique customers who visited (clicked any product in) a specified department over a given time range. Ensure correct mapping from product_id to its department and avoid double-counting users who clicked multiple products/categories within the same department. Explain your indexing/partitioning strategy for large-scale data and how you would extend the query to return results for all departments.

Loading comments...