SLA hit rate by metric

hardSQL~35 min · 4 tests · helpdesk

slas stores two targets per priority side by side: first_response_hours and resolve_hours. That wide shape is fine for reading, but awkward for reporting, where you want one row per priority and metric.

Report how often each target was met. Return one row per (priority, metric) with:

column type meaning
priority text the priority
metric text 'first_response' or 'resolve'
target_hours integer the target from slas
tickets integer tickets measured for this metric
met_pct decimal percentage of those tickets that met the target, rounded to 1 decimal

How to measure:

  • first_response: from the ticket’s opened_at to its earliest first_response event in ticket_events. Tickets with no first_response event aren’t measured.
  • resolve: from opened_at to closed_at. Open tickets (closed_at is NULL) aren’t measured.
  • A ticket meets a target when the time taken is less than or equal to the target. Exactly on target counts as met.
  • Leave out any (priority, metric) pair with no measured tickets.

Row order doesn’t matter.

Tables: tickets, ticket_events, slas.

solution.sqlDuckDB · helpdesk

Press ⌘ ↵ or Run to check the visible tests. Submit runs the hidden ones too. Everything runs in your browser.

⌘ ↵ to run