Transpose a table using query in Access

前端 未结 1 923
攒了一身酷
攒了一身酷 2021-01-17 02:03

I have the table1, i want to transpose it as shown in table1_1, can anyone tell me the query/function that can be used to do this

table 1

FileName            


        
相关标签:
1条回答
  • 2021-01-17 02:33

    Have a look at crosstab queries used with Min, Max and Last.

    Transpose:

    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;
    

    Normalize:

    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 
    
    0 讨论(0)
提交回复
热议问题