Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
MQL to SQL Conversion SQL
00:00
5 left

MQL to SQL Conversion SQL

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate the month-over-month conversion rate of leads moving from marketing qualified lead (MQL) to sales qualified lead (SQL) for Pagerduty.

Use the provided lead and stage-event data. Count each lead at most once in its MQL month, and only count an SQL event occurring at or after that lead's MQL timestamp. Leads with a NULL MQL timestamp are ignored.

Output

  1. One row per MQL month, ordered chronologically.
  2. Columns: month, mql_count, sql_converted_count, conversion_rate_pct, and mom_change_pct_points.
  3. mom_change_pct_points is the change from the previous month's conversion rate and is NULL for the first month.

Schema

leads
ColumnTypeDescription
lead_idPKINTUnique identifier for the lead
mql_atTIMESTAMPTimestamp when the lead became marketing qualified
lead_sourceVARCHAR(50)Marketing source associated with the lead
lead_stage_events
ColumnTypeDescription
event_idPKINTUnique identifier for the stage event
lead_idINTLead associated with the stage event
stageVARCHAR(30)Lifecycle stage recorded by the event
event_atTIMESTAMPTimestamp when the stage event occurred
Tablesleadslead_stage_events
Interviewer

Your question is MQL to SQL Conversion SQL. 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.