Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Consecutive Logins with Ranking
00:00
5 left

Consecutive Logins with Ranking

MediumSQL · PostgreSQL

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
Interviewer

Your question is Consecutive Logins with Ranking. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.