日期:2014-05-16 浏览次数:20605 次
create table TB1 (CI nvarchar(10),[频点1 ] real,[频点2] real,[频点3] real,[频点4] real,[频点5] real,[频点6] real,[频点7] real,[频点8] real)
insert into TB1 values('1',11,12,23,14,15,16,null,null)
insert into TB1 values('2',21,22,23,24,25,26,27,null)
insert into TB1 values('3',31,32,33,34,35,36,37,38)
create table TB1 (CI nvarchar(10),[频点] real)
insert into TB1 values('1',11)
insert into TB1 values('1',12)
insert into TB1 values('1',13)
insert into TB1 values('1',14)
insert into TB1 values('1',15)
insert into TB1 values('1',16)
insert into TB1 values('2',21)
insert into TB1 values('2',22)
insert into TB1 values('2',23)
insert into TB1 values('2',24)
insert into TB1 values('2',25)
insert into TB1 values('2',26)
insert into TB1 values('2',27)
insert into TB1 values('3',31)
insert into TB1 values('3',32)
insert into TB1 values('3',33)
insert into TB1 values('3',34)
insert into TB1 values('3',35)
insert into TB1 values('3',36)
insert into TB1 values('3',37)
insert into TB1 values('3',38)
--第一個問題:
select CI ,[频点] from #TB1
unpivot
(
[频点] for x in
([频点1 ],[频点2],[频点3],[频点4],[频点5],[频点6],[频点7],[频点8])
) a
--第二個問題:
create table #TB1 (CI nvarchar(10),[頻點] real)
insert into #TB1 values('1',11)
insert into #TB1 values('1',12)
insert into #TB1 values('1',13)
insert into #TB1 values('1',14)
insert into #TB1 values('1',15)
insert into #TB1 values('1',16)
insert into #TB1 values('2',21)
insert into #TB1 values('2',22)
insert into #TB1 values('2',23)
insert into #TB1 values('2',24)
insert into #TB1 values('2',25)
insert into #TB1 values('2',26)
insert into #TB1 values('2',27)
insert into #TB1 values('3',31)
insert into #TB1 values('3',32)
insert