-4

enter image description here

how to convert like this row into column

neer
  • 4,031
  • 6
  • 20
  • 34
  • Some [MCVE](https://stackoverflow.com/help/mcve) please, CREATE TABLE and INSERT VALUES would really help. – KtX2SkD May 24 '17 at 08:20
  • What you are looking for is a `pivot`. [Convert Rows to columns using 'Pivot' in SQL Server](https://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server) is the answer for your question. – Rigerta May 24 '17 at 08:21
  • Attention to readers, column 1 is case-sensitive, column 2 skips some values, e.g. 304 skipped since for the same column 1 value, 305 exists. – KtX2SkD May 24 '17 at 08:27

1 Answers1

0

try this

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
Esperento57
  • 16,521
  • 3
  • 39
  • 45