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 KPI Pivot Report
00:00
5 left

SQL KPI Pivot Report

MediumSQL · PostgreSQL

Problem

Business Context

Datavant Link operations needs a monthly report showing several linkage KPIs in a pivot-style result, with one row per organization and month.

Task

Write a PostgreSQL query that reports production Datavant Link runs from January 1 through March 31, 2025. Use conditional aggregation to place multiple KPIs in separate columns.

Requirements

  1. Group results by calendar month and organization, labeling missing organizations as Unknown.
  2. Return total runs, completed runs, total input records, matched records, completed-run match rate as a percentage, and average processing time in minutes.
  3. Include failed and pending production runs in total run counts, but calculate match rate and average processing time only from completed runs. Avoid division by zero.
  4. Sort by month ascending and organization name ascending.

Schema

organizations
ColumnTypeDescription
organization_idPKINTEGERUnique organization identifier
organization_nameVARCHAR(100)Organization display name
linkage_runs
ColumnTypeDescription
run_idPKINTEGERUnique linkage run identifier
organization_idINTEGEROrganization associated with the run
started_atTIMESTAMPTime at which the run started
completed_atTIMESTAMPTime at which the run completed
run_statusVARCHAR(20)Current run status
environmentVARCHAR(20)Execution environment
input_recordsINTEGERNumber of records submitted
matched_recordsINTEGERNumber of records successfully matched
Tablesorganizationslinkage_runs
Interviewer

Your question is SQL KPI Pivot Report. Start with the requirements and the two 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.