Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.