日期:2014-05-17 浏览次数:20556 次
drop table #tb;
Create table #tb([year] int, m int ,mt float);
Use tempdb;
Insert Into #tb(year,m,mt)
Select 1991 as [year] ,1 as m ,1.1 as mt Union ALl
select 1991 ,2 ,1.2 Union ALl
select 1991 , 3 , 1.3 Union ALl
select 1991 ,4 , 1.4 Union ALl
select 1992 , 1 , 2.1 Union ALl
select 1992, 2 ,2.2 Union ALl
select 1992 ,3 ,2.3 Union ALl
select 1992 ,4 ,2.4
Select Max(Case when m = 1 then mt end) as m1,
Max(Case when m = 2 then mt end) as m2,
Max(Case when m = 3 then mt end) as m3,
Max(Case when m = 4 then mt end) as m4
From #tb
Group by [year]