주세요.
CREATE TABLE
[dbo].[TypeCount](
[TypeName] [nvarchar](5) NULL,
[pYear] [int] NULL,
[pMonth] [int] NULL,
[cnt] [int] NULL
) ON [PRIMARY]
--INSERT INTO [TypeCount]
([TypeName],[pYear],[pMonth],[cnt]) VALUES ('A', 2015, 4, 30)
--INSERT INTO [TypeCount] ([TypeName],[pYear],[pMonth],[cnt])
VALUES ('B', 2015, 4, 20)
--INSERT INTO [TypeCount]
([TypeName],[pYear],[pMonth],[cnt]) VALUES ('A', 2015, 3, 20)
--INSERT INTO [TypeCount]
([TypeName],[pYear],[pMonth],[cnt]) VALUES ('B', 2015, 3, 10)
select TypeName
, sum(A_042015) as '04/2015', sum(A_032015)
as '03/2015'
, sum(B_042015) as '04/2015', sum(B_032015)
as '03/2015'
from
(
select TypeName
, Case When pYear = 2015 and pMonth = 4 and
TypeName = 'A' Then cnt End 'A_042015'
, Case When pYear = 2015 and pMonth = 3 and
TypeName = 'A' Then cnt End 'A_032015'
, Case When pYear = 2015 and pMonth = 4 and
TypeName = 'B' Then cnt End 'B_042015'
, Case When pYear = 2015 and pMonth = 3 and
TypeName = 'B' Then cnt End 'B_032015'
from TypeCount
where
TypeName in ('A', 'B')
) as x
group by TypeName