Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
User Engagement Metrics Query
00:00
5 left

User Engagement Metrics Query

MediumSQL · PostgreSQL

Problem

Write a SQL query to extract user engagement metrics over a specific time frame.

Use the users and engagement_events tables for events from 2024-01-01 inclusive through 2024-01-08 exclusive. Include users with no events during the timeframe.

Output

  1. One row per user, with user_id, username, total_events, active_days, likes, comments, and shares.
  2. Sort by total_events descending, then user_id ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
usernameVARCHAR(100)Display name of the user
engagement_events
ColumnTypeDescription
event_idPKINTUnique engagement event identifier
user_idINTUser associated with the event
occurred_atTIMESTAMPTimestamp when the event occurred
event_typeVARCHAR(20)Engagement type, such as like, comment, or share
Tablesusersengagement_events
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.