展开全部
--测试环境MSSQL2008
--建表
create table T
(
Field Varchar(10)
)
--插入数据
insert into T values('a'),('b'),('c'),('d')
--表二
;
With CT
As
(
Select *,ROW_NUMBER() over(order by Field) as id
From t
)
Select A.Field As [1],B.Field As [2] From CT A cross join CT B
Where A.id<B.id
Order by A.Field
--表三
;
With CT
As
(
Select *,ROW_NUMBER() over(order by Field) as id
From t
)
Select A.Field As [1],B.Field As [2] ,C.Field As [3] From CT A cross join CT B
cross join CT C
Where A.id<B.id and B.id<C.id
Order by A.Field
--表四
Select * From
(
Select *,ROW_NUMBER() over(order by Field) as id From t
)S
pivot
(
max(Field)
For
id in([1],[2],[3],[4])
)P
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询