Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL: Min and Max Per User

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

Your question is SQL: Min and Max Per User. 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

Robinhood monitors access to resources in the Robinhood app, such as account statements and tax documents. Write a PostgreSQL query that reports each user’s earliest and latest recorded access time.

Requirements

  1. Return every user, including users with no access-log records.
  2. Calculate the earliest access as first_access_at and latest access as last_access_at using timestamp aggregation.
  3. Return the user ID and username, ordered by user_id ascending.
  4. Preserve NULL values for users whose access history is unavailable.

Schema

users
ColumnTypeDescription
user_idPKBIGINTUnique Robinhood user identifier
usernameVARCHAR(100)User display name
account_statusVARCHAR(20)Current account status
access_logs
ColumnTypeDescription
access_idPKBIGINTUnique access event identifier
user_idBIGINTUser associated with the access event
resource_nameVARCHAR(100)Robinhood resource accessed
accessed_atTIMESTAMPTZTimestamp when the resource was accessed
event_typeVARCHAR(30)Access event type
Tablesusersaccess_logs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results