首页 > 解决方案 > 将多列转置为 2 列

问题描述

想保留 ID,但将每个产品列转置为 1 个产品列。从

ID      Product 1   Product 2   Product 3
1111    Apple       Cherry      Peach
2222                            Apple
3333    Chery       Cherry  

ID      Products        
1111    Apple       
1111    Cherry      
1111    Peach       
2222            
2222            
2222    Apple       
3333    Chery       
3333    Cherry      
3333

标签: ms-access

解决方案


使用联合查询:

Select ID, [Product 1] As Products
From YourTable
Union All
Select ID, [Product 2] As Products
From YourTable
Union All
Select ID, [Product 3] As Products
From YourTable
Order By ID, Products


推荐阅读