Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Compute Avg Days to First Reaction

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

Your question is Compute Avg Days to First Reaction. Start with the requirements and the two 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

Meta wants to measure how quickly people react after starting a conversation in Messenger. Write a SQL query to calculate the average number of days from each conversation's start time to the first reaction used in that conversation.

Requirements

  1. Use the conversations table to get each conversation start time.
  2. Use the message_reactions table to find the first reaction timestamp per conversation.
  3. Return only conversations that have at least one reaction.
  4. Output the average delay in days across all qualifying conversations, rounded to 2 decimal places.

Schema

conversations
ColumnTypeDescription
conversation_idPKBIGINTPrimary key for the conversation thread
thread_typeVARCHAR(20)Surface type such as dm, group, or fb_groups
started_atTIMESTAMPTimestamp when the conversation started
message_reactions
ColumnTypeDescription
reaction_idPKBIGINTPrimary key for the reaction event
conversation_idBIGINTForeign key to conversations.conversation_id
reacted_atTIMESTAMPTimestamp when the reaction was used
reaction_typeVARCHAR(20)Reaction type such as like, love, haha, wow, care, or sad
Tablesconversationsmessage_reactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results