0

我有 table1,我想将它转置为 table1_1 所示,谁能告诉我可以用来执行此操作的查询/函数

表格1

FileName    ObjectName  Column1 Column2 Column3 Column4 Column5

F1           Line1         A       B       C      D       E
F1           Line2         F       G       H      I       J
F1           Line3         K       L       M      N       O


table1_1


FileName    ObjectName       Column    Data
F1            Line1          Column1    A
F1            Line1          Column2    B
F1            Line1          Column3    C
F1            Line1          Column4    D
F1            Line1          Column5    E
F1            Line2          Column1    F
F1            Line2          Column2    G
F1            Line2          Column3    H
F1            Line2          Column4    I
F1            Line2          Column5    J
F1            Line3          Column1    K
F1            Line3          Column2    L
F1            Line3          Column3    M
F1            Line3          Column4    N
F1            Line3          Column5    O
4

1 回答 1

3

查看与 Min、Max 和 Last 一起使用的交叉表查询。

转置:

TRANSFORM First(Table1_1.Data) AS FirstOfData
SELECT Table1_1.FileName, Table1_1.ObjectName
FROM Table1_1
GROUP BY Table1_1.FileName, Table1_1.ObjectName
PIVOT Table1_1.Column;

标准化:

SELECT FileName, ObjectName, "Column1" As ColName, Column1 As ColData  
FROM Table1 
UNION ALL
SELECT FileName, ObjectName, "Column2" As ColName, Column2 As ColData  
FROM Table1 
UNION ALL
SELECT FileName, ObjectName, "Column3" As ColName, Column3 As ColData  
FROM Table1 
UNION ALL
SELECT FileName, ObjectName, "Column4" As ColName, Column4 As ColData  
FROM Table1 
UNION ALL
SELECT FileName, ObjectName, "Column5" As ColName, Column5 As ColData  
FROM Table1 
于 2012-04-18T13:35:32.070 回答