Здесь вы можете найти решение вашего вопроса с помощью PIVOT:
create table #Table1 (Sources varchar(10), Priority varchar (5), Counts int)
insert into #Table1 values ('Email','P4',19)
insert into #Table1 values ('Phone','P3',27)
insert into #Table1 values ('Email','P3',53)
insert into #Table1 values ('Outlook','P4',77)
insert into #Table1 values ('Email','P2',12)
SELECT Sources,ISNULL([P4],0) AS P4,ISNULL([P3],0) AS P3,ISNULL([P2],0) AS P2,ISNULL([P1],0) AS P1
FROM
(
SELECT Sources,
Priority,
Counts
FROM #Table1
) AS SourceTable PIVOT(SUM(Counts) FOR Priority IN([P4],[P3],[P2],[P1])) AS PivotTable;
Надеюсь, он будет вам полезен! Пока!