Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL KPI Pivot Report

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

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

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