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
High-Throughput Write Schema Design
00:00
5 left

High-Throughput Write Schema Design

MediumSQL · PostgreSQL

Problem

How do you design a database schema that supports high-throughput write operations while maintaining data integrity for Press Ganey?

For this SQL exercise, use the supplied schema to identify the latest represented ingestion batch for each organization and assess its event and answer coverage.

Output

  1. Return one row per organization with at least one represented batch.
  2. Include organization_code, batch_id, received_at, event counts, answer coverage percentage, and the prior batch event count.
  3. Sort by received_at descending, then organization_code ascending. Rows with a NULL received_at are ignored.

Output details

  • Return columns in this order: organization_code, batch_id, received_at, event_count, answered_event_count, answer_count, answer_coverage_pct, prior_event_count.
  • Select the latest batch by received_at descending, breaking ties with batch_id descending.
  • Define prior_event_count using chronological received_at ascending order, breaking ties with batch_id ascending.
  • Count only non-NULL answer_value values in answer_count.
  • Count an event as answered when it has at least one non-NULL answer_value.
  • Round answer_coverage_pct to two decimal places as answered events divided by total events times 100.

Schema

organizations
ColumnTypeDescription
organization_idPKUUIDStable organization identifier
organization_codeVARCHAR(40)Organization code
created_atTIMESTAMPTZOrganization creation timestamp
ingestion_batches
ColumnTypeDescription
batch_idPKUUIDIngestion batch identifier
source_systemVARCHAR(40)Source system name
received_atTIMESTAMPTZBatch receipt timestamp
row_countINTEGERRows received in the batch
survey_events
ColumnTypeDescription
event_idPKUUIDSurvey event identifier
event_received_atTIMESTAMPTZEvent ingestion timestamp
organization_idUUIDOwning organization
batch_idUUIDSource ingestion batch
source_record_numberINTEGERRecord position within the source batch
occurred_atTIMESTAMPTZEvent occurrence timestamp
event_typeSMALLINTEvent type code
payloadJSONBOriginal event payload
event_answers
ColumnTypeDescription
answer_idPKBIGINTAnswer identifier
event_idUUIDRelated survey event
question_codeVARCHAR(40)Survey question code
answer_valueVARCHAR(200)Submitted answer value
recorded_atTIMESTAMPTZAnswer recording timestamp
Tablesorganizationsingestion_batchessurvey_eventsevent_answers
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the four tables are in the Question tab.

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.