다음 스크립트를 작성했지만 불행히도 막혔습니다. 현재는행을 1로 합치고 금액을 합계
SELECT dim1 AS Costc,
period AS Period,
sum(actual) AS Beds,
CASE
WHEN measure LIKE 'beds%' THEN ISNULL(sum(actual), 0)
END AS BEDS,
CASE
WHEN measure LIKE 'occu%' THEN ISNULL (sum(actual), 0)
END AS OCCU,
measure
FROM statistics
WHERE measure IN (SELECT measure
FROM statistics
WHERE measure LIKE 'beds%'
OR measure LIKE 'occu%')
AND dim1 = 'ABC'
AND period = '201301'
GROUP BY period,
dim1,
measure
반환
를 읽고COSTC | Period | Beds | BEDS | OCCU | Measure
ABC | 201301 | 40 | 40 | NULL | beds_abc
ABC | 201301 | 35 | 35 | NULL | beds_def
ABC | 201301 | 30 | NULL | 30 | occu_abc
ABC | 201301 | 20 | NULL | 20 | occu_def
내 원하는 출력은
COSTC | Period | BEDS | OCCU
ABC | 201301 | 75 | 50
입니다 어떤 도움을 감사
외부의 집계를 이동해야? –