Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Consecutive Logins with Ranking

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Consecutive Logins with Ranking. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

CACI International's analytics team is reviewing access patterns in a mission operations platform. Write a PostgreSQL query to identify users who logged in on consecutive calendar days.

The query should treat multiple sessions on the same calendar date as one login day. Return only streaks containing at least two consecutive login dates.

Requirements

  1. Join session_logs to users to include the user's name.
  2. Deduplicate multiple sessions from the same user on the same calendar date.
  3. Use ROW_NUMBER() and date arithmetic to assign each consecutive sequence to a streak.
  4. Return the streak start date, end date, and number of login days, ordered by user and streak start date.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique user identifier
user_nameVARCHAR(100)User display name
session_logs
ColumnTypeDescription
session_idPKINTEGERUnique session identifier
user_idINTEGERUser associated with the session
login_atTIMESTAMPSession start timestamp
Tablesuserssession_logs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results