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
SQL Joins and Conditional Aggregations
00:00
5 left

SQL Joins and Conditional Aggregations

HardSQL · PostgreSQL

Problem

Catalist needs a campaign-level view of outreach performance for campaigns launched during September 2025. Write a PostgreSQL query that joins campaigns, constituents, and outreach events, while preserving campaigns with no matching constituents or events.

Requirements

  1. Return September 2025 campaigns with their district and total distinct constituents.
  2. Count distinct constituents with completed outreach and completed outreach that received a positive response.
  3. Calculate the completed-outreach percentage using conditional aggregation, avoiding division by zero.
  4. Include only campaigns with at least one completed outreach, and order by completed-outreach percentage descending, then campaign name.

Schema

campaigns
ColumnTypeDescription
campaign_idPKINTEGERUnique campaign identifier
campaign_nameVARCHAR(100)Name of the Catalist outreach campaign
districtVARCHAR(50)Geographic district
start_dateDATECampaign launch date
constituents
ColumnTypeDescription
constituent_idPKINTEGERUnique constituent identifier
campaign_idINTEGERCampaign assigned to the constituent
postal_codeVARCHAR(10)Constituent postal code
outreach_events
ColumnTypeDescription
event_idPKINTEGERUnique outreach event identifier
constituent_idINTEGERConstituent contacted during the event
event_statusVARCHAR(20)Outcome status of the outreach event
responseVARCHAR(20)Recorded constituent response
duration_minutesINTEGERDuration of the outreach event
event_dateDATEDate the outreach occurred
Tablescampaignsconstituentsoutreach_events
Interviewer

Your question is SQL Joins and Conditional Aggregations. Start with the requirements and the three 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.