Skip to content
RED SAGSkills

Ticket First Response Time

ticket_replies holds replies on support tickets. author_type is agent or customer.

For every ticket, compute the minutes between tickets.created_at and the first agent reply, rounded with ROUND(x, 2). Customer replies do not count. Tickets with no agent reply get NULL.

Return columns ticket_id, first_response_minutes. Order by ticket_id ascending.

Schema

CREATE TABLE tickets (
  ticket_id INTEGER PRIMARY KEY,
  subject TEXT NOT NULL,
  created_at TEXT NOT NULL
);
CREATE TABLE ticket_replies (
  reply_id INTEGER PRIMARY KEY,
  ticket_id INTEGER NOT NULL,
  author_type TEXT NOT NULL,
  replied_at TEXT NOT NULL
);

Sample data

tickets

ticket_idsubjectcreated_at
1Cannot log in2026-04-10 09:00:00
2Refund request2026-04-10 10:30:00
3Bug in export2026-04-10 11:15:00
4Change plan2026-04-11 08:00:00

ticket_replies

reply_idticket_idauthor_typereplied_at
11agent2026-04-10 09:20:00
21customer2026-04-10 09:25:00
32customer2026-04-10 10:35:00
42agent2026-04-10 12:00:00
53customer2026-04-10 11:30:00
61agent2026-04-10 09:10:00
Hint 1

Put the author_type = 'agent' condition in the LEFT JOIN's ON clause. In WHERE it would drop tickets that have no agent reply.

Hint 2

strftime('%s', ts) gives Unix seconds. Divide the difference by 60.0 to get minutes.

Good practice for: Data Analyst, Product Manager, Backend Developer, Business Analyst

SQL (SQLite)

Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.