Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Referrers Driving Recent Signups

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

Your question is Top Referrers Driving Recent Signups. 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

Instagram Growth wants to identify which referrers are driving the most new account signups in the last 30 days. Write a SQL query to return the top 3 referrers by number of signups.

Requirements

  1. Count only users whose signup_date falls within the last 30 days relative to DATE '2024-06-30'.
  2. Attribute each signup to the referrer in referral_events using referred_user_id.
  3. Exclude rows where the referrer name is NULL.
  4. Return the top 3 referrers ordered by signup count descending, then referrer name ascending for tie-breaking.
  5. Output columns: referrer_name, signup_count.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
full_nameVARCHAR(100)User's display name
signup_dateDATEDate the user signed up
referral_events
ColumnTypeDescription
referral_idPKINTUnique referral event identifier
referred_user_idINTUser who signed up from a referral
referrer_nameVARCHAR(100)Name of the referrer source or partner
referrer_surfaceVARCHAR(50)Meta surface where the referral originated
Tablesusersreferral_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results