我通过excel使用Microsoft.ACE.OLEDB.12.0
连接在我的工作簿中进行内部查询。
如何插入Year
列与我在查询中的年份并订购它们以便它们不在一起。那么他们会一个接一个地重复?
我添加了Year
专栏,但现在订购是问题。
这是我当前的查询
select [Data Type], [Currency], [Book Name], [1987] as Value
from [stage2$]
UNION ALL
select [Data Type], [Currency], [Book Name], [1990]
from [stage2$]
当前数据:
+--------------------------------+----------+-------+---------------+
| Data Type | Currency | Name | value |
+--------------------------------+----------+-------+--------------
| Missing Non Historical Results | BSD | Carib | (279) |
| Missing Non Historical Results | BSD | Carib | 18 |
| Missing Non Historical Results | BSD | Carib | 898 |
| Missing Non Historical Results | BSD | Carib | (50) |
+--------------------------------+----------+-------+---------------+
预期结果:
+--------------------------------+----------+-------+---------------+---------+
| Data Type | Currency | Name | Year | value |
+--------------------------------+----------+-------+---------------+---------+
| Missing Non Historical Results | BSD | Carib | 1987 | (279) |
| Missing Non Historical Results | BSD | Carib | 1990 | 898 |
| Missing Non Historical Results | BSD | Carib | 1987 | 18 |
| Missing Non Historical Results | BSD | Carib | 1990 | (50) |
+--------------------------------+----------+-------+---------------+---------+
您可以在select
语句中添加另一列:
select [Data Type], [Currency], [Book Name], '1987' as Year, [1987] as Value
from [stage2$]
UNION ALL
select [Data Type], [Currency], [Book Name], '1990' as Year, [1990]
from [stage2$]
order by Year