Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Activity and User Metrics

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

Your question is SQL for Activity and User Metrics. Start with the requirements and the three 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

ZoomInfo Technologies wants a daily view of activity volume in ZoomInfo Engage. Write a PostgreSQL query that reports activity and distinct-user counts by reportable activity type and calendar date.

Requirements

  1. Use the reporting range from 2025-01-01 through 2025-01-04, inclusive.
  2. Include every reportable activity type on every date, including combinations with no activities.
  3. Return the number of activities and distinct users who performed those activities. Activities without an associated user count toward activity volume but not the user count.
  4. Add the previous day's activity and user counts for the same activity type using a window function.
  5. Calculate day-over-day changes for both measures, preserving NULL for the first date because no prior date exists.
  6. Order results by activity type and activity date.

Schema

users
ColumnTypeDescription
user_idPKINTUnique ZoomInfo Engage user identifier
full_nameVARCHAR(100)User's display name
activity_types
ColumnTypeDescription
activity_type_idPKINTUnique activity type identifier
activity_typeVARCHAR(80)Name of the activity type
is_reportableBOOLEANIndicates whether the type appears in reporting
activities
ColumnTypeDescription
activity_idPKINTUnique activity identifier
activity_type_idINTReferenced activity type
user_idINTUser who performed the activity
activity_timestampTIMESTAMPTimestamp when the activity occurred
Tablesusersactivity_typesactivities
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results