-1

これをケースステートメントとして書き直そうとしています:

 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」付近の構文が正しくありません。

複数の列名の構文を理解できません。助けてください。ありがとう。

4

1 に答える 1

1

これは私が意味したものです

CASE WHEN PRIORITY='1' then  (ID)   END as 'BlockerIn',
CASE WHEN PRIORITY='2' then  (ID)  END  as 'CriticalOut'

これにより、値を含む 2 つの列が作成されます。

複数の値を持つ1つの列が必要な場合は、そうします

CASE WHEN PRIORITY='1' then  'BlockerIn' 
WHEN PRIORITY='2' then  'CriticalOut' END  AS Priority
于 2012-05-28T14:21:33.433 に答える