我正在尝试将其重写为案例陈述:
SELECT dateadd(day, -@Day, getdate()) AS Dt
,COUNT(pkey) AS 'BlockerOut'
FROM tablename
WHERE PROJECT='10270' AND RESOLUTION='1'
AND CREATED>dateadd(day, -(30+@Day), getdate()) AND CREATED<dateadd(day, -@Day, getdate())
AND PRIORITY='1' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))>4) t1
JOIN
(SELECT dateadd(day, -@Day, getdate()) AS Dt
,COUNT(pkey) AS 'BlockerIn'
FROM jobissue
WHERE PROJECT='10270' AND RESOLUTION='1'
AND CREATED>dateadd(day, -(30+@Day), getdate()) AND CREATED<dateadd(day, -@Day, getdate())
AND PRIORITY='1' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))<=4) t2
ON t1.Dt = t2.Dt
我已经走到了这一步,无法弄清楚如何比列更进一步
SELECT dateadd(day, -@Day, getdate()) AS Dt,
CASE
WHEN PRIORITY='1' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))<=4 then (pkey) end 'BlockerIn'
FROM [jobissue]
WHERE PROJECT='10270' AND RESOLUTION='1'
AND CREATED>dateadd(day, -(30+@Day), getdate()) AND CREATED<dateadd(day, -@Day, getdate())
group by PRIORITY, CREATED, resolutiondate, pkey
这行得通..但是对于两列我得到一个错误:
SELECT dateadd(day, -@Day, getdate()) AS Dt,
CASE
WHEN PRIORITY='1' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))<=4 then (pkey) 'BlockerIn'
WHEN PRIORITY='2' AND (DATEDIFF(hour, [CREATED], [RESOLUTIONDATE]))>24 then (pkey) 'CriticalOut'
end
FROM jobissue
WHERE PROJECT='10270' AND RESOLUTION='1'
AND CREATED>dateadd(day, -(30+@Day), getdate()) AND CREATED<dateadd(day, -@Day, getdate())
group by PRIORITY, CREATED, resolutiondate, pkey
消息 102,级别 15,状态 1,第 18 行“BlockerIn”附近的语法不正确。
我无法计算出多个列名的语法。请帮帮我?谢谢。