Archive data query examples
concept australia Updated Sep 10, 2026 1 min read archive-data-query-examples.md
Query examples demonstrate how to combine live and archive data for IT operations reporting, customer service case history, and HR compliance audits.
IT operations: incident volume and MTTR
Report on incident volume and MTTR (mean time to resolve) over a rolling three-year period, broken down by priority and assignment group.
SQL
SELECT date_trunc('month', opened_at) AS month, priority, DV(assignment_group) AS group_name, COUNT(*) AS incident_count, AVG( CASE WHEN closed_at IS NOT NULL THEN CAST( (CAST(closed_at AS FLOAT) - CAST(opened_at AS FLOAT)) * 1440 AS FLOAT) END ) AS avg_mttr_minutesFROM ( SELECT opened_at, closed_at, priority, assignment_group FROM incident WHERE opened_at >= date_trunc('month', CAST(NOW() AS DATE) - INTERVAL '36 months') UNION ALL SELECT opened_at, closed_at, priority, assignment_group FROM ar_incident WHERE opened_at >= date_trunc('month', CAST(NOW() AS DATE) - INTERVAL '36 months')) AS three_year_historyGROUP BY month, priority, DV(assignment_group)ORDER BY month DESC, priority ASC;Customer service: full case history for an account
Return all cases for a specific account over five years, regardless of whether they are still active or have been archived.
SQL
SELECT number, short_description, priority, state, opened_at, closed_at, resolved_by, 'live' AS sourceFROM sn_customerservice_caseWHERE account = 'Acme Corporation' AND opened_at >= '2020-01-01'
UNION ALL
SELECT number, short_description, priority, state, opened_at, closed_at, resolved_by, 'archive' AS sourceFROM ar_sn_customerservice_caseWHERE account = 'Acme Corporation' AND opened_at >= '2020-01-01'
ORDER BY opened_at ASC;HR and compliance: employee request history
Return all service requests associated with a specific employee across their full tenure. Because archive tables store resolved display values, filter directly on the display name without resolving a sys_id.
SQL
SELECT number, short_description, category, opened_at, closed_at, state, requested_for, 'live' AS sourceFROM sc_requestWHERE requested_for = 'Jane Smith' OR opened_by = 'Jane Smith'
UNION ALL
SELECT number, short_description, category, opened_at, closed_at, state, requested_for, 'archive' AS sourceFROM ar_sc_requestWHERE requested_for = 'Jane Smith' OR opened_by = 'Jane Smith'
ORDER BY opened_at ASC;Keywords archive dataSQL queryUNION ALLincident reportingcase history
122 lines · 3.2 KB
---
title: Archive data query examples
description: Query examples demonstrate how to combine live and archive data for IT operations reporting, customer service case history, and HR compliance audits.
locale: en-US
canonical_url: https://www.servicenow.com/docs/r/australia/servicenow-platform/archive-data-query-examples.html
release: australia
topic_type: concept
last_updated: "2026-09-10"
reading_time_minutes: 1
keywords: [archive data, SQL query, UNION ALL, incident reporting, case history]
breadcrumb: [Live Archive, Explore, RaptorDB Professional, Extend ServiceNow AI Platform capabilities]
---
# Archive data query examples
Query examples demonstrate how to combine live and archive data for IT operations reporting, customer service case history, and HR compliance audits.
## IT operations: incident volume and MTTR
Report on incident volume and MTTR \(mean time to resolve\) over a rolling three-year period, broken down by priority and assignment group.
```
SELECT
date_trunc('month', opened_at) AS month,
priority,
DV(assignment_group) AS group_name,
COUNT(*) AS incident_count,
AVG(
CASE WHEN closed_at IS NOT NULL
THEN CAST(
(CAST(closed_at AS FLOAT) - CAST(opened_at AS FLOAT)) * 1440
AS FLOAT)
END
) AS avg_mttr_minutes
FROM (
SELECT opened_at, closed_at, priority, assignment_group
FROM incident
WHERE opened_at >= date_trunc('month',
CAST(NOW() AS DATE) - INTERVAL '36 months')
UNION ALL
SELECT opened_at, closed_at, priority, assignment_group
FROM ar_incident
WHERE opened_at >= date_trunc('month',
CAST(NOW() AS DATE) - INTERVAL '36 months')
) AS three_year_history
GROUP BY month, priority, DV(assignment_group)
ORDER BY month DESC, priority ASC;
```
## Customer service: full case history for an account
Return all cases for a specific account over five years, regardless of whether they are still active or have been archived.
```
SELECT
number,
short_description,
priority,
state,
opened_at,
closed_at,
resolved_by,
'live' AS source
FROM sn_customerservice_case
WHERE account = 'Acme Corporation'
AND opened_at >= '2020-01-01'
UNION ALL
SELECT
number,
short_description,
priority,
state,
opened_at,
closed_at,
resolved_by,
'archive' AS source
FROM ar_sn_customerservice_case
WHERE account = 'Acme Corporation'
AND opened_at >= '2020-01-01'
ORDER BY opened_at ASC;
```
## HR and compliance: employee request history
Return all service requests associated with a specific employee across their full tenure. Because archive tables store resolved display values, filter directly on the display name without resolving a `sys_id`.
```
SELECT
number,
short_description,
category,
opened_at,
closed_at,
state,
requested_for,
'live' AS source
FROM sc_request
WHERE requested_for = 'Jane Smith'
OR opened_by = 'Jane Smith'
UNION ALL
SELECT
number,
short_description,
category,
opened_at,
closed_at,
state,
requested_for,
'archive' AS source
FROM ar_sc_request
WHERE requested_for = 'Jane Smith'
OR opened_by = 'Jane Smith'
ORDER BY opened_at ASC;
```
| title | Archive data query examples |
| description | Query examples demonstrate how to combine live and archive data for IT operations reporting, customer service case history, and HR compliance audits. |
| locale | en-US |
| canonical_url | https://www.servicenow.com/docs/r/australia/servicenow-platform/archive-data-query-examples.html |
| release | australia |
| topic_type | concept |
| last_updated | 2026-09-10 |
| reading_time_minutes | 1 |
| keywords | archive dataSQL queryUNION ALLincident reportingcase history |
| breadcrumb | Live ArchiveExploreRaptorDB ProfessionalExtend ServiceNow AI Platform capabilities |