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
Top Referrers Driving Recent Signups
00:00
5 left

Top Referrers Driving Recent Signups

MediumSQL · PostgreSQL

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
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.