Another approach using CTE and Joins.
declare @table table(Proce int, type char(1), addi int, sub int, multi int, div int)
insert into @table values
(1,'A', 1, 0, 1, 1),
(1,'B', 2, 2, 0, 1);
;with cte_a as
(
SELECT proce, max(addi) as Aadd, max(sub) as Asub, max(multi) as Amulti, max(div) as Adiv
FROM @table where type="A"
group by proce
),cte_b as
(
SELECT proce, max(addi) as Badd, max(sub) as Bsub, max(multi) as Bmulti, max(div) as Bdiv
FROM @table where type="B"
group by proce
)
SELECT a.proce,a.aAdd, a.aSub, a.Amulti, a.Adiv,b.BAdd,b.bsub, b.bmulti, b.bdiv
from cte_a as a
join cte_b as b
on a.Proce = b.Proce
proce | aAdd | aSub | Amulti | Adiv | BAdd | bsub | bmulti | bdiv |
---|---|---|---|---|---|---|---|---|
1 | 1 | 0 | 1 | 1 | 2 | 2 | 0 | 1 |
solved Query to get a output in desired format