logo

Back to questions

Repeat Purchases on Multiple Days

Medium

This is the same question as problem #7 in the SQL Chapter of Ace the Data Science Interview!

Assume you are given the table below containing information on user purchases. Write a query to obtain the number of users who purchased the same product on two or more different days. Output the number of unique users.

Table:

Column NameType
user_idinteger
product_idinteger
quantityinteger
purchase_datedatetime

Example Input:

user_idproduct_idquantitypurchase_date
5363223601/11/2022 12:33:44
82735853502/20/2022 14:05:26
5363223503/02/2022 09:33:28
53614351003/02/2022 08:40:00
82724524504/09/2022 00:00:00

Example Output:

users_num
1

PostgreSQL 14

Refer friends to get bonus content & cool prizes.