Explain how you use SQL joins and stored procedures to transform data in a pipeline, and describe how you validate the results end to end.
Use the provided PostgreSQL tables to implement a refresh procedure for the case summary table. Include all source cases, calculate event metrics, resolve the latest assignment and event, and account for cases without matching records.
Output
- Return one row per source case with
case_id, customer_ref, team, priority, event_count, total_handle_minutes, latest_status, and first_response_minutes.
- Include cases without events or assignments, use
Unassigned where the current team is unavailable, and order by total_handle_minutes descending, then case_id ascending.
Output details
- Break ties for the latest assignment by descending
assignment_id after descending effective_at.
- Break ties for the latest event by descending
event_id after descending event_ts.
- Return
event_count as 0 and total_handle_minutes as 0.00 when a case has no events.
- Return
NULL for latest_status and first_response_minutes when those values are unavailable.
- Round
total_handle_minutes and first_response_minutes to two decimal places.