我正在尝试从以下类似的数据库中计算时间平均时差和票数:
[TicketId | OpenedDateTime | ResponseDateTime | Category ]
[12345 | 2018-11-11 15:03:02 | 2018-11-11 15:08:19 | Helpdesk ]
[12346 | 2018-11-11 15:06:00 | 2018-11-11 15:18:26 | Helpdesk ]
[12347 | 2018-11-11 15:09:58 | 2018-11-11 15:11:11 | Support ]
[12348 | 2018-11-11 15:11:33 | 2018-11-11 15:28:56 | Headphones]
[12349 | 2018-11-11 15:12:12 | 2018-11-11 15:15:15 | Support ]
目前,我逐行计算OpenedDateTime和ResponseDateTime之间的时间差。
SELECT
[OpenedDateTime],
[ResponseDateTime],
RIGHT('0' + LTRIM(convert(varchar(5),DateDiff(s, [OpenedDateTime], [ResponseDateTime])/3600)), 2) + ':' +
RIGHT('0' + LTRIM(convert(varchar(5),DateDiff(s, [OpenedDateTime], [ResponseDateTime])%3600/60)), 2) + ':' +
RIGHT('0' + LTRIM(convert(varchar(5),(DateDiff(s, [OpenedDateTime], [ResponseDateTime])%60))), 2) as 'TimeDifference'
FROM
[dbo].[ticket]
我最后需要做的是:
[Category | TotalTickets | AverageResponseTime]
[Helpdesk | 2 | 00:09:11 ]
[Support | 2 | 00:02:33 ]
[Headphones | 1 | 00:17:23 ]
关于如何实现此目标的任何建议?