Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Joins and Conditional Aggregations

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

Your question is SQL Joins and Conditional Aggregations. 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results