Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Clean Incomplete Salesforce Lead Records

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

Your question is Clean Incomplete Salesforce Lead Records. Start with the requirements and the three 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

You are given Salesforce CRM lead records with missing values in owner, region, and lead source fields. Write a PostgreSQL query that prepares the data for analysis by returning one cleaned row per lead created in January 2024. Use the assigned owner when available, otherwise fall back to the queue owner; standardize missing region and lead_source values into explicit labels; and classify each lead as ready_for_analysis only when both email and annual revenue are present.

Schema

salesforce_leads
ColumnTypeDescription
lead_idPKINTUnique lead identifier
account_idINTRelated Salesforce account
assigned_owner_idINTDirectly assigned Salesforce owner
queue_owner_idINTFallback Salesforce queue owner
created_dateDATELead creation date
regionVARCHAR(50)Sales region, may be NULL or blank
lead_sourceVARCHAR(50)Lead acquisition source
emailVARCHAR(100)Lead email address
annual_revenueNUMERIC(12,2)Reported annual revenue
salesforce_users
ColumnTypeDescription
user_idPKINTSalesforce user identifier
user_nameVARCHAR(100)User or queue display name
user_roleVARCHAR(50)Role for the user or queue
salesforce_accounts
ColumnTypeDescription
account_idPKINTSalesforce account identifier
account_nameVARCHAR(100)Account name
industryVARCHAR(50)Account industry
Tablessalesforce_leadssalesforce_userssalesforce_accounts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results