2013-05-10 3 views
0

나는이 다음 표 : 당신은 2과 열의 이름을 포함하지 않았다SQL 결과 두 개의 열

name  totalstatus1 totalstatus2 total 
ricardo 2   4    6 
+0

이 ig는 소리가 날 것 같지만 2 개가 사용하고 있습니까? 첫 번째 행의 값 또는 두 번째 행의 값? 거기에 샘플을 게시 할 수 있습니까? 반복되는 값이 없으므로 모두 볼 수 있습니다. –

답변

4

: 나는 선택이 같이 반환 할 수 있도록 할 방법

Full name status 
ricardo 1 2 
ricardo 2 4 

4하지만이 비슷한을 사용할 수

select name, 
    sum(case when status = 1 then value end) totalStatus1, 
    sum(case when status = 2 then value end) totalStatus2, 
    sum(value) Total 
from yourtable 
group by name; 

참조을