Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL: Active User Query

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

Your question is SQL: Active User Query. 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

Palantir Foundry telemetry includes user accounts and recorded activity events. Write a PostgreSQL query to identify the most active user during January 2025.

Requirements

  1. Include every user in the activity calculation, including users with no qualifying events.
  2. Count each activity event from 2025-01-01 inclusive through 2025-02-01 exclusive.
  3. Return the user ID, user name, activity count, and timestamp of the user's latest qualifying activity.
  4. Return only the most active user. Break ties by latest activity timestamp, then by the smallest user ID.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique user identifier
user_nameVARCHAR(100)User display name
team_nameVARCHAR(100)Foundry team associated with the user
activity_events
ColumnTypeDescription
event_idPKINTEGERUnique activity event identifier
user_idINTEGERUser associated with the event, when known
event_typeVARCHAR(50)Activity category
occurred_atTIMESTAMPTimestamp when the event occurred
Tablesusersactivity_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results