Calculate Weekly Thread Engagement with Reactions in SQL
Company: Meta
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: Medium
Interview Round: Onsite
messages
+------------+--------+----------+--------------+---------------------+
| message_id | sender | receiver | has_reaction | timestamp |
+------------+--------+----------+--------------+---------------------+
| 101 | 12 | 34 | 1 | 2023-04-01 10:00:00 |
| 102 | 34 | 12 | 0 | 2023-04-01 10:02:00 |
| 103 | 56 | 78 | 1 | 2023-04-02 14:35:00 |
| 104 | 78 | 56 | 1 | 2023-04-02 14:40:00 |
| 105 | 90 | 91 | 0 | 2023-04-03 09:12:00 |
+------------+--------+----------+--------------+---------------------+
##### Scenario
Messaging platform stores every message with sender, receiver, reaction flag, and timestamp. Analysts need weekly thread-level engagement insights.
##### Question
Write SQL to count the number of unique threads that had at least one message during a given week. Write SQL to count how many of those threads contain at least one message where has_reaction = 1. For threads that eventually get a reaction, compute the average time (in minutes) from the first message in the thread to the first reacted message. Describe how you would use the presence or absence of reactions to define an "active" thread for an A/B test.
##### Hints
Treat a thread as an unordered sender-receiver pair; use DISTINCT, aggregation, window functions, and TIMESTAMPDIFF.
Quick Answer: This question evaluates SQL and data-manipulation competency for computing time-based engagement metrics, specifically forming thread-level aggregates and measuring reaction occurrence and timing.