Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Window Streak of QuickBooks Logins

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

Your question is SQL Window Streak of QuickBooks Logins. 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

Intuit wants to identify continuous daily login streaks for users of QuickBooks. Write a PostgreSQL query that detects each uninterrupted sequence of login dates and excludes streaks shorter than two days.

Requirements

  1. Treat multiple QuickBooks login events by the same user on the same calendar date as one login day.
  2. Use a window function such as ROW_NUMBER, LAG, or LEAD to identify consecutive date sequences.
  3. Return each qualifying streak's user, start date, end date, and number of consecutive login days.
  4. Include only streaks of at least two days and order the results by user ID and streak start date.

Schema

quickbooks_users
ColumnTypeDescription
user_idPKINTEGERUnique QuickBooks user identifier
display_nameVARCHAR(100)User's display name
emailVARCHAR(255)User email address
quickbooks_login_events
ColumnTypeDescription
login_event_idPKINTEGERUnique login event identifier
user_idINTEGERReferences quickbooks_users.user_id
login_dateDATECalendar date of the login
login_sourceVARCHAR(30)Login channel, when available
Tablesquickbooks_usersquickbooks_login_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results