转置一个简单的访问表

时间:2015-02-27 03:09:36

标签: ms-access access-vba transpose

有人问过类似的问题,但我没有能够适用于我的情况。

我创建了这个简单的求和查询来计算我2 Tag Core Count查询中每列的值的数量:

SELECT Count([CORE_DATA].[TAG NUMBER]) AS [TAG NUMBER], 
Count([CORE_DATA].[TAG STATUS]) AS [TAG STATUS], 
Count([CORE_DATA].[UNIT NUMBER]) AS [UNIT], 
Count([CORE_DATA].[FUNCTIONAL CLASS]) AS [FUNCTIONAL CLASS] 
    FROM CORE_DATA;

这完全没问题。除了我的情况,我需要对结果表进行转置。例如。字段1包含上述查询TAG NUMBER, TAG STATUS, UNIT NUMBER and FUNCTIONAL CLASS和字段2中的列标题以包含相应的计数。

你怎么能实现这个目标?

1 个答案:

答案 0 :(得分:0)

想出来。这对我有用

SELECT 'TAG NUMBER' as [Attribute Value], [TAG NUMBER] as Count
FROM [2 Tag Core Count]
UNION ALL
SELECT 'TAG STATUS' as [Attribute Value], [TAG STATUS] as Count
FROM [2 Tag Core Count]
UNION ALL
SELECT 'UNIT' as [Attribute Value], [UNIT] as Count
FROM [2 Tag Core Count]
UNION ALL
SELECT 'FUNCTIONAL CLASS' as [Attribute Value], [FUNCTIONAL CLASS] as Count
FROM [2 Tag Core Count];