我有一个看起来是这个样子的3和3个重复行的表...MS SQL集团行
Column1 | Column2
CustomerID | 22
CustomerName | ”ABC”
Responsible | ”Allan”
CustomerID | 23
CustomerName | ”DEF”
Responsible | ”Jessica”
CustomerID | 24
CustomerName | ”GHI”
Responsible | ”Paul”
下面的脚本可以用来创建表并填充它样本数据...
CREATE TABLE Responsible
([ RowType ] VARCHAR(12),
[ Value ] VARCHAR(9))
;
INSERT INTO Responsible
([RowType],
[ Value ])
VALUES
('CustomerID',
'22'),
('CustomerName',
'ABC'),
('Responsible',
'Allan'),
('CustomerID',
'23'),
('CustomerName',
'DEF'),
('Responsible',
'Jessica'),
('CustomerID',
'24'),
('CustomerName',
'GHI'),
('Responsible',
'Paul');
而且我想获得它像一个表,看起来像这样:
CustomerID | CustomerName | Responsible
22 | ABC | Allan
23 | DEF | Jessica
24 | GHI | Paul
什么是最好的前进方向?
什么数据库引擎?你没有任何领域可以在你的桌子上分组吗? – Blag
您正在使用哪些DBMS? Postgres的?甲骨文? –
你不能这样做。 SQL表格表示*无序*行。如果没有指定顺序的列,则无法可靠地连接行。 –