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
Monthly KPI SQL With Joins
00:00
5 left

Monthly KPI SQL With Joins

MediumSQL · PostgreSQL

Problem

The Nature Conservancy needs a monthly operational KPI view for regional management reporting. Write a PostgreSQL query that combines program activity and finance data without double-counting either source.

Requirements

  1. Return every region for January through March 2024, including months with no activity or spending.
  2. Calculate active programs, completed deliverables, completed operational hours, and actual spend by region and month.
  3. Compare each month's spend with the prior month using LAG.
  4. Return zero for missing monthly activity or finance values and order by region and month.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique regional identifier
region_nameVARCHAR(100)Name of the operating region
programs
ColumnTypeDescription
program_idPKINTUnique program identifier
region_idINTOwning region
program_nameVARCHAR(150)Program name
program_activities
ColumnTypeDescription
activity_idPKINTUnique activity identifier
program_idINTRelated conservation program
activity_dateDATEDate of the activity
activity_statusVARCHAR(30)Operational status
hoursNUMERIC(10,2)Hours recorded for the activity
finance_transactions
ColumnTypeDescription
transaction_idPKINTUnique finance transaction identifier
program_idINTProgram charged for the transaction
transaction_dateDATETransaction posting date
amountNUMERIC(12,2)Transaction amount
expense_categoryVARCHAR(60)Finance expense category
Tablesregionsprogramsprogram_activitiesfinance_transactions
Interviewer

Your question is Monthly KPI SQL With Joins. Start with the requirements and the four 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.