Repeat Purchase

ASKED IN INTERVIEW
4pts
e Bay

Problem Statement

Find users who purchased the same item on two or more different days.

Rules:

  • Output columns: user_id, item_id, repeat_count.
  • repeat_count is the number of unique days the user bought the item.
  • Ignore multiple purchases of the same item on the same day.
  • Results must be sorted by repeat_count in descending order, then by user_id in ascending order.
Tests your understanding of
Filtering, Aggregation and Date Handling

Input Tables

users
user_id(INTEGER)username(VARCHAR)
1shopper_alt
2bid_master
3collect_all
4daily_buyer
5guest_user
items
item_id(INTEGER)item_name(VARCHAR)
501AA Batteries
502USB-C Cable
503Vintage Watch
purchases
purchase_id(INTEGER)user_id(INTEGER)item_id(INTEGER)purchase_date(DATE)
115012024-01-01
215012024-02-01
325012024-01-05
425012024-01-05
535022024-01-10
635022024-01-15
735022024-01-20
845032024-01-01

Expected Output

user_id(INTEGER)item_id(INTEGER)repeat_count(INTEGER)
35023
15012

Tags

MediumASKED IN INTERVIEWFilteringAggregationDate Handling
15-20 min
50%

Hints