Analyze Customer Purchase Patterns Using SQL Query
Company: DoorDash
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates a candidate's competence with SQL data manipulation and windowing concepts, specifically using ordering and partitioning to compare and rank events within a customer's purchase history.
Tables
orders(order_id INTEGER, customer_id INTEGER, order_value DECIMAL(10,2), order_date DATE, city VARCHAR(2))
Hints
- Use LAG(order_value) OVER (PARTITION BY customer_id ORDER BY order_date DESC) to get the previous order_value per customer.
- Use RANK() and PERCENT_RANK() OVER (PARTITION BY customer_id ORDER BY order_date DESC) for recency ranking within each customer.