これをケースステートメントとして書き直そうとしています:
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
これは機能します..しかし、2つの列でエラーが発生します:
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」付近の構文が正しくありません。
複数の列名の構文を理解できません。助けてください。ありがとう。