-4
A
답변
0
시도하는 방법이
select model_cod, ver_num,
sum(case when mod_cls in ('KM', 'KS') then cost else 0 end) as [KM/KS],
sum(case when mod_cls ='PL' then cost else 0 end) as PL,
sum(case when mod_cls ='PI' then cost else 0 end) as PI,
sum(case when mod_cls in ('KM', 'KS', 'PL', 'PI') then cost else 0 end) as Total
from yourtable
group by model_cod, ver_num
+0
오류 토큰 합계가 유효하지 않습니다. 유효한 토큰 : from, –
+0
'비용'열의 유형은 무엇입니까? 이 열에 항상 숫자가 있습니까? – Esperento57
+0
고마워요 그 일을 –
일부 [MCVE] (https://stackoverflow.com/ help/mcve) 제발, CREATE TABLE과 INSERT VALUES가 도움이 될 것입니다. – KtX2SkD
당신이 찾고있는 것은'피벗'입니다. [행을 SQL Server의 'Pivot'을 사용하여 열로 변환] (https://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server) 질문에 대한 대답입니다. . –
독자의주의 1 열 1은 대소 문자를 구분하며 2 열은 일부 값을 건너 뜁니다 (예 : 동일한 컬럼 1 값에 대해 305가 존재하므로 304가 생략되었습니다. – KtX2SkD