사례 명세서 (또는 제안한 내용)에 여러 결과가 나타나고 여러 결과가 출력에 반영되도록하고 싶습니다. 그러나 하단의 예제를 사용하여 원하는 결과를 얻지 못합니다. 미리 감사드립니다.T-SQL : 열 값을 행 값으로 옮깁니다.
ID Phase Total Hours Team1 Team2 Team3
1 Test 50 25 10 15
2 QA 60 20 20 20
3 Impl 40 0 20 20
찾고 : :
현재ID Phase Total Hours Team Name Team Hour
1 Test 50 Team 1 25
1 Test 50 Team 2 10
1 Test 50 Team 3 15
2 QA 60 Team 1 20
2 QA 60 Team 2 20
2 QA 60 Team 3 20
3 Impl 40 Team 2 20
3 Impl 40 Team 3 20
Select ID, Phase, Total Hours,
case
When Team1 is not null and Team1 is >0 then 'Team1'
When Team2 is not null and Team2 is >0 then 'Team2'
When Team3 is not null and Team3 is >0 then 'Team3'
end as 'Team Name',
case
When Team1.Hrs is not null and Team1.Hrs is >0 then Team1.Hrs
When Team2.Hrs is not null and Team2.Hrs is >0 then Team2.Hrs
When Team3.Hrs is not null and Team3.Hrs is >0 then Team3.Hrs
end as 'Team Hours'
From DB.DBNAME
샘플 쿼리는 무엇을 생성합니까? – JNK