Skip to content

2228. Users With Two Purchases Within Seven Days 👍

1
2
3
4
5
6
7
8
9
SELECT DISTINCT First.user_id
FROM Purchases AS First
INNER JOIN purchases AS Second
  USING (user_id)
WHERE
  First.purchase_id != Second.purchase_id
  AND First.purchase_date <= Second.purchase_date
  AND DATEDIFF(Second.purchase_date, First.purchase_date) <= 7
ORDER BY 1;