这是我现在的整个查询,第一部分似乎很好,但从“Y as”开始,它显示所有用红色下划线的列。我用粗体标出了一个显示红色下划线的语句。我需要计算SLA的百分比,这是我无法通过此查询得出的。营业时间为周六至周日上午4:30至下午5:30,周一至周五上午4:30至晚上10:30。
SELECT
[JOB_TICKET].[JOB_TICKET_ID],
[JOB_TICKET].[REPORT_DATE],
[JOB_TICKET].[FIRST_RESPONSE_DATE],
[JOB_TICKET].CLOSE_DATE,
,[JOB_TICKET].LAST_UPDATED,
[PRIORITY_TYPE].[PRIORITY_TYPE_NAME] AS 'Ticket_Priority' ,
DATEDIFF(MINute, report_date,FIRST_RESPONSE_DATE) as 'time_to_accept' ,
sum (CASE
WHEN (DATEDIFF(MINute,report_date,FIRST_RESPONSE_DATE) <= '10' )
THEN 1
ELSE 0
END) AS "SLA time_to_accept Status",
DATEDIFF(MINUTE,[JOB_TICKET].[FIRST_RESPONSE_DATE],[JOB_TICKET].[CLOSE_DATE]) as 'time_to_resolve' ,
(CASE
when PRIORITY_TYPE_NAME='low'
then sum(case
when DATEDIFF(MINUTE,[JOB_TICKET].[FIRST_RESPONSE_DATE],[JOB_TICKET].[CLOSE_DATE]) <= '960'
then 1
else 0
end )
when PRIORITY_TYPE_NAME='medium'
then sum(case
when DATEDIFF(MINUTE[JOB_TICKET].[FIRST_RESPONSE_DATE],[JOB_TICKET].[CLOSE_DATE]) <= '480'
then 1
else 0
end )
when PRIORITY_TYPE_NAME='high'
then sum(case
when DATEDIFF(MINUTE,[JOB_TICKET].[FIRST_RESPONSE_DATE],[JOB_TICKET]. [CLOSE_DATE]) <= '120'
then 1
else 0
end )
when PRIORITY_TYPE_NAME='Urgent'
then sum(case
when DATEDIFF(MINUTE,[JOB_TICKET].[FIRST_RESPONSE_DATE],[JOB_TICKET]. [CLOSE_DATE]) <= '60'
then 1
else 0
end)
end) as "Closed within SLA" FROM [SWHD01].[dbo].[JOB_TICKET] INNER JOIN [SWHD01].[dbo].[STATUS_TYPE] ON [JOB_TICKET].[STATUS_TYPE_ID] =[STATUS_TYPE].[STATUS_TYPE_ID] INNER JOIN [SWHD01].[dbo].[PROBLEM_TYPE] ON [JOB_TICKET].[PROBLEM_TYPE_ID] = [PROBLEM_TYPE].[PROBLEM_TYPE_ID] INNER JOIN [SWHD01].[dbo].[PRIORITY_TYPE] ON [JOB_TICKET].[PRIORITY_TYPE_ID] = [PRIORITY_TYPE].[PRIORITY_TYPE_ID] where REPORT_DATE is not null and DATEDIFF(MINUTE,[JOB_TICKET].[FIRST_RESPONSE_DATE],[JOB_TICKET].[CLOSE_DATE]) is not null and DATEDIFF(MINUTE,[JOB_TICKET].[FIRST_RESPONSE_DATE],[JOB_TICKET].[CLOSE_DATE]) > 0 group by JOB_TICKET_ID,[JOB_TICKET].[REPORT_DATE],[JOB_TICKET].[FIRST_RESPONSE_DATE],
[JOB_TICKET].CLOSE_DATE,[JOB_TICKET].LAST_UPDATED,[PRIORITY_TYPE].[PRIORITY_TYPE_NAME]
答案 0 :(得分:0)
time_to_accept
和time_to_resolve
,因此请使用CTE,这样您就不必重复这些长DATEDIFF
个表达式。 CASE
个表达式
time_to_accept and
time_to_resolve。 FROM
的{{1}}声明;我添加了SELECT
作为占位符。
FROM SomeTable