如何将此行转换为列
答案 0 :(得分: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