declare @T table ([id] int identity(1,1) primary key, month int, sum money, acc int)
insert into @T
values(1, 100, 10000),
(2, 300, 10000),
(3, 100.35, 10000),
(4, 710, 10000),
(5, 32, 10000),
(6, 10, 10000),
(7, 11, 10000),
(8, 21, 10000),
(9, 35.70, 10000),
(10, 3254.12, 10000),
(11, 123.12, 10000),
(12, 200.56, 10000),
(1, 103, 10000),
(2, 304, 10000),
(3, 105.35, 10000),
(4, 7140, 10000),
(5, 334, 10000),
(6, 1434, 10000),
(7, 134, 10000),
(8, 2343, 10000),
(9, 352.70, 10000),
(10, 324.12, 10000),
(11, 1233.12, 10000),
(12, 1004.56, 10000),
(1, 200.56, 20000),
(2, 456.54, 20000),
(3, 987.35, 20000),
(4, 710.45, 20000),
(5, 32.32, 20000),
(6, 10.12, 20000),
(7, 11.24, 20000),
(8, 987.41, 20000),
(9, 135.70, 20000),
(10, 324.12, 20000),
(11, 1235.12, 20000),
(12, 679.56, 20000),
(1, 700.00, 20000),
(2, 304.32, 20000),
(3, 105.35, 20000),
(4, 7800, 20000),
(5, 3340, 20000),
(6, 145, 20000),
(7, 1340, 20000),
(8, 2300, 20000),
(9, 3520.70, 20000),
(10, 3240.12, 20000),
(11, 1200.12, 20000),
(12, 10.00, 20000)
--select acc, month, sum from @T
select acc, [1] sum01, [2] sum02, [3] sum03, [4] sum04, [5] sum05, [6] sum06,
[7] sum07, [8] sum08, [9] sum09, [10] sum10, [11] sum11, [12] sum12,
[1]+[2]+[3]+[4]+[5]+[6]+[7]+[8]+[9]+[10]+[11]+[12] sumTotal
from (select acc, month, sum from @T) t
pivot
(
sum(sum) for month in ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])
) p