Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Top Lead Sources Query
00:00
5 left

Top Lead Sources Query

MediumSQL · PostgreSQL

Problem

Cvent wants to compare lead-source performance across the last three completed calendar quarters. Write a PostgreSQL query that evaluates every lead source, including sources with no leads in the reporting period.

For each source, calculate total leads, qualified leads, and the percentage of leads whose status is qualified. Rank sources by qualified-lead count, qualification rate, total-lead count, and source name as deterministic tie-breakers.

Output

  1. Return at most three rows, with one row per ranked lead source.
  2. Include source_rank, source_name, total_leads, qualified_leads, and qualification_rate.
  3. Use the three completed quarters ending before the fixed reporting boundary of July 1, 2026.
  4. Include sources with no matching leads, treating their counts as zero and their qualification rate as NULL.
  5. Sort by source_rank ascending. NULL rates must sort after non-NULL rates when ranking.

Schema

lead_sources
ColumnTypeDescription
source_idPKINTUnique identifier for a Cvent lead source
source_nameVARCHAR(100)Display name of the lead source
leads
ColumnTypeDescription
lead_idPKINTUnique identifier for a lead
source_idINTLead source identifier
created_atDATEDate the lead was created
lead_statusVARCHAR(30)Current lead status
Tableslead_sourcesleads
Interviewer

Your question is Top Lead Sources Query. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.