Return userid and the length of their longest run of CONSECUTIVE daily logins (longeststreak). Table definitions (from…
SQLLevel: AdvancedGaps, islands and streaks
Return user_id and the length of their longest run of CONSECUTIVE daily logins (longest_streak).
Table definitions (from the source exercise):
CREATE TABLE logins(login_id INTEGER PRIMARY KEY, user_id INTEGER, login_date TEXT);
Hints
- Define one output row and the source-table keys.
- Check duplicates, NULLs and the order of filtering and aggregation.
Answer
This answer is part of mentoring
Advanced questions come with a full breakdown and a mock interview with a working quant researcher. The first call is free.
Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT