将行作为列返回Microsoft Access SQL查询

时间:2014-04-10 08:18:50

标签: sql ms-access

我有以下查询

SELECT o.ea_guid as CLASSGUID, o.Object_Type as CLASSTYPE, 
       o.Name, type.Property, type.Value
FROM ((t_object as o
       INNER JOIN t_objectproperties as type
         ON o.Object_ID = type.Object_ID)

返回结果如下

Name         Property        Value
Result1      Location        Queens
Result1      Size            King
Result1      Cost            100
Result2      Location        Queens
Result2      Special         Christmas
Result2      Cost            10

我想要的是

Name        Location        Size         Special          Cost
Result1     Queens          King                          100
Result2     Queens                       Christmas        10

我如何构建这样的查询?

1 个答案:

答案 0 :(得分:3)

旧的交叉表查询怎么样?

TRANSFORM First([Value]) AS FirstOfValue
SELECT [Name]
FROM
    (
        SELECT o.Name, type.Property, type.Value
        FROM t_object as o
               INNER JOIN t_objectproperties as type
                 ON o.Object_ID = type.Object_ID
    )
GROUP BY [Name]
PIVOT [Property] IN ('Location','Size','Special','Cost')