如何在Access 2010中模拟UNPIVOT?

And*_*ler 9 sql sql-server ms-access unpivot ms-access-2010

UNPIVOT在MS SQL Server 2005中可用,但AFAIK不在MS Access 2010中.如何使用板载方式实现?例如,我有一张桌子

ID | A | B | C | Key 1 | Key 2 | Key 3
---------------------------------------
 1 | x | y | z |     3 |   199 |   452
 2 | x | y | z |    57 |   234 |   452
Run Code Online (Sandbox Code Playgroud)

并希望有一个像这样的表

ID | A | B | C | Key
--------------------
 1 | x | y | z |   3
 2 | x | y | z |  57
 1 | x | y | z | 199
 2 | x | y | z | 234
 2 | x | y | z | 452
Run Code Online (Sandbox Code Playgroud)

关键452是一个特例.目前我在OLEDB/ATL C++中进行旋转.虽然它足够快但我仍然很好奇.这里Access 2010最有效的SQL语句是什么?

Han*_*sUp 12

这个查询......

SELECT ID, A, B, C, [Key 1] AS key_field
FROM tblUnpivotSource
UNION ALL
SELECT ID, A, B, C, [Key 2] AS key_field
FROM tblUnpivotSource
UNION ALL
SELECT ID, A, B, C, [Key 3] AS key_field
FROM tblUnpivotSource;
Run Code Online (Sandbox Code Playgroud)

...返回此记录集(使用您的示例表值为tblUnpivotSource)...

ID A B C key_field
-- - - - ---------
 1 x y z         3
 2 x y z        57
 1 x y z       199
 2 x y z       234
 1 x y z       452
 2 x y z       452
Run Code Online (Sandbox Code Playgroud)