Quick Overview

This question evaluates proficiency in SQL-based data aggregation and ranking techniques applied to event logs, testing skills such as grouping, counting, and the use of window/ranking functions to identify top users by date.

Identify Top Three Active Users by Event Date

Company: Meta

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Onsite

event_log +------------+---------+-----------+---------------------+ | event_date | user_id | event_type| event_timestamp | +------------+---------+-----------+---------------------+ | 2025-06-01 | 123 | click | 2025-06-01 10:15:00 | | 2025-06-01 | 123 | view | 2025-06-01 10:16:00 | | 2025-06-01 | 456 | click | 2025-06-01 11:00:00 | | 2025-06-02 | 123 | click | 2025-06-02 09:00:00 | | 2025-06-02 | 789 | view | 2025-06-02 12:30:00 | +------------+---------+-----------+---------------------+ ##### Scenario Meta onsite interview for a Data Engineer/Data Scientist role; interviewer wants to test SQL depth on product event logs. ##### Question Given the event_log table, write a SQL query that returns the three most active users (by event count) for every event_date, ordered by activity. ##### Hints Aggregate counts, apply ROW_NUMBER() over each date partition, then filter where row_number <= 3.

Overview: This question evaluates proficiency in SQL-based data aggregation and ranking techniques applied to event logs, testing skills such as grouping, counting, and the use of window/ranking functions to identify top users by date.

Given the event_log table, write a SQL query that returns the three most active users (by event count) for every event_date, ordered by activity.

Tables

event_log(event_date DATE, user_id INTEGER, event_type VARCHAR, event_timestamp TIMESTAMP)

Hints

  1. Aggregate counts per (event_date, user_id).
  2. Apply ROW_NUMBER() over each event_date partition ordered by event_count DESC (and user_id ASC as a tiebreaker), then filter to row_number <= 3.
MetaData ScientistmediumData Manipulation (SQL/Python)

Top 3 Most Active Users Per Day

Given the event_log table, write a SQL query that returns the three most active users (by event count) for every event_date, ordered by activity.

Expected Output

For each event_date, return up to three users with the highest number of events (event_count). Break ties deterministically by user_id ascending. Include columns: event_date, user_id, event_count, activity_rank. Order the output by event_date and activity_rank.

Tables

event_log
event_log
ColumnType
event_dateDATE
user_idINTEGER
event_typeVARCHAR
event_timestampTIMESTAMP

Comments (1)

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Language
Run code to see results here.

Browse More Questions