SQL Hard Interview Question
SQL Hard Interview Question
PRAGYA RATHI
---
---
---
4. Consecutive Purchases/Logins
Task: Find users with 3+ consecutive days of activity.
WITH user_dates AS (
SELECT
user_id,
event_date,
LAG(event_date, 2) OVER (PARTITION BY user_id ORDER BY event_date) AS prev_date
FROM activity
)
SELECT DISTINCT user_id
FROM user_dates
WHERE event_date - prev_date = 2;
---
---
---
---
---
---