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
- Return one row per organization with at least one represented batch.
- Include
organization_code, batch_id, received_at, event counts, answer coverage percentage, and the prior batch event count.
- 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.