我需要帮助实现以下输出。 我有一张桌子
declare @tblLevels table(
levelsID INT IDENTITY(1,1),
levelNumber INT,
levelDesc VARCHAR(100))
insert into @tblLevels(levelNumber,levelDescription)
values
(1,'L1D1'),
(1,'L1D2'),
(1,'L1D3'),
(1,'L1D4'),
(2,'L2D1'),
(2,'L2D2'),
(2,'L2D3'),
(2,'L2D4'),
(3,'L3D1'),
(3,'L3D2'),
(3,'L3D3')
select * from @tblLevels
levelsID levelNumber levelDesc
========================================
1 1 L1D1
2 1 L1D2
3 1 L1D3
4 1 L1D4
5 2 L2D1
6 2 L2D2
7 2 L2D3
8 2 L2D4
9 3 L3D1
10 3 L3D2
11 3 L3D3
我有另一个表(@tblLevelSpreadOut),其结构如下所示
declare @tblLevelSpreadOut table(
levelSpreadOutID INT IDENTITY(1,1),
levelNumber1 INT,
levelDesc1 VARCHAR(100),
levelNumber2 INT,
levelDesc2 VARCHAR(100),
levelNumber3 INT,
levelDesc3 VARCHAR(100))
需要从前一个表(@tblLevels)填充,以便输出
select levelNumber1, levelDesc1, levelNumber2 ,levelDesc2 , levelNumber3 ,levelDesc3
from @tblLevelSpreadOut
levelNumber1 levelDesc1 levelNumber2 levelDesc2 levelNumber3 levelDesc3
============================================================================
1 L1D1 2 L2D1 3 L3D1
1 L1D1 2 L2D1 3 L3D2
1 L1D1 2 L2D1 3 L3D3
1 L1D1 2 L2D2 3 L3D1
1 L1D1 2 L2D2 3 L3D2
1 L1D1 2 L2D2 3 L3D3
1 L1D1 2 L2D3 3 L3D1
1 L1D1 2 L2D3 3 L3D2
1 L1D1 2 L2D3 3 L3D3
1 L1D1 2 L2D4 3 L3D1
1 L1D1 2 L2D4 3 L3D2
1 L1D1 2 L2D4 3 L3D3
1 L1D2 2 L2D1 3 L3D1
1 L1D2 2 L2D1 3 L3D2
1 L1D2 2 L2D1 3 L3D3
1 L1D2 2 L2D2 3 L3D1
1 L1D2 2 L2D2 3 L3D2
1 L1D2 2 L2D2 3 L3D3
1 L1D2 2 L2D3 3 L3D1
1 L1D2 2 L2D3 3 L3D2
1 L1D2 2 L2D3 3 L3D3
1 L1D2 2 L2D4 3 L3D1
1 L1D2 2 L2D4 3 L3D2
1 L1D2 2 L2D4 3 L3D3
1 L1D3 2 L2D1 3 L3D1
1 L1D3 2 L2D1 3 L3D2
1 L1D3 2 L2D1 3 L3D3
1 L1D3 2 L2D2 3 L3D1
1 L1D3 2 L2D2 3 L3D2
1 L1D3 2 L2D2 3 L3D3
1 L1D3 2 L2D3 3 L3D1
1 L1D3 2 L2D3 3 L3D2
1 L1D3 2 L2D3 3 L3D3
1 L1D3 2 L2D4 3 L3D1
1 L1D3 2 L2D4 3 L3D2
1 L1D3 2 L2D4 3 L3D3
感谢所有回复的人以及所有看过这个问题的人。
答案 0 :(得分:-1)
您想要一个完整的外部联接?
尝试
select
t.levelNumber1,
t.levelDesc1,
t.levelNumber2 ,
t.levelDesc2 ,
t.levelNumber3 ,
t.levelDesc3
from
@tblLevelSpreadOut t outer join
@tblLevelSpreadOut t2
order by
t.levelDesc1,
t.levelDesc2 ,
t.levelDesc3
另外,请考虑接受问题的答案。您将从社区获得更好的回复。