在Access中使用查询转置表

时间:2012-04-18 13:33:50

标签: ms-access ms-access-2007

我有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

1 个答案:

答案 0 :(得分:3)

查看与Min,Max和Last一起使用的crosstab queries

移调:

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