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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Joining Mismatched Datasets
00:00
5 left

Joining Mismatched Datasets

MediumSQL · PostgreSQL

Problem

Describe your approach to joining datasets with mismatched primary keys or differing aggregation levels.

Use the provided tables to reconcile daily campaign metrics with monthly campaign targets. Include only metric records whose external key maps to a campaign, while retaining target-only campaign months.

Output

  1. One row per campaign and month
  2. Columns: campaign_id, month_start, total_spend, total_conversions, target_conversions, and conversion_variance
  3. Include all mapped metric months and target months, with missing measures represented as zero
  4. Order by campaign_id, then month_start

Schema

campaign_key_map
ColumnTypeDescription
campaign_idPKINTInternal campaign identifier
external_campaign_keyVARCHAR(30)Campaign key used by the metrics source
campaign_nameVARCHAR(100)Campaign display name
daily_campaign_metrics
ColumnTypeDescription
metric_idPKINTDaily metric record identifier
external_campaign_keyVARCHAR(30)External campaign key from the source system
metric_dateDATEDate of the metric record
spendNUMERIC(12,2)Daily campaign spend
conversionsINTDaily conversion count
monthly_campaign_targets
ColumnTypeDescription
target_idPKINTMonthly target record identifier
campaign_idINTInternal campaign identifier
month_startDATEFirst day of the target month
target_segmentVARCHAR(30)Optional target segment
target_conversionsINTConversion target for the segment and month
Tablescampaign_key_mapdaily_campaign_metricsmonthly_campaign_targets
Interviewer

Your question is Joining Mismatched Datasets. 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.