SQL
Lab
Microsoft Microsoft Interview Question 04

Support Ticket
Resolution
Time

Calculate average resolution time per support category.

Table Schema

Inspect
Table

interactive
ColumnType
ticket_idinteger
categoryvarchar
created_atdatetime
resolved_atdatetime

Sample Data

Input
Output

Sample Input: tickets
ticket_idcategorycreated_atresolved_at
1Billing09:0010:00
2Tech10:0012:00
3Billing11:0012:00
4Tech13:0015:00
5Account14:0016:00
Expected Output
categoryavg_resolution_time
Account2 hours
Billing1 hour
Tech2 hours

SQL Editor

Run
Query

postgresql
Waiting for query

categoryavg_resolution_time
Account2 hours
Billing1 hour
Tech2 hours

Hints

Unlock
Clues

Hint 01: Identify the grouping level required by the output.
Hint 02: Aggregate with COUNT, SUM, AVG, or a window function as needed.
Hint 03: Filter after aggregation with HAVING or after ranking with an outer query.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT category, AVG(resolved_at - created_at) AS avg_resolution_time
FROM tickets
GROUP BY category;

Explanation

Step By
Step

01

Read the expected output columns to determine the final grain.

02

Aggregate or rank the input rows to calculate the requested metric.

03

Filter, sort, and alias the final columns to match the output.

Related Questions

Keep
Solving