Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Count Distinct Users by Day

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

Your question is Count Distinct Users by Day. Start with the requirements and the one table 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

Shopify Analytics needs a daily activity metric showing how many unique users interacted with Shopify Admin. Write a PostgreSQL query using the user_events table.

Requirements

  1. Group events by calendar day, derived from event_timestamp.
  2. Count each user_id at most once per day, excluding events without a timestamp or user ID.
  3. Return results in ascending date order with the columns activity_day and distinct_users.

Schema

user_events
ColumnTypeDescription
event_idPKBIGINTUnique event identifier
user_idBIGINTShopify user who generated the event
event_timestampTIMESTAMPTimestamp when the event occurred
event_nameVARCHAR(100)Name of the recorded event
Tablesuser_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results