反转列和行

时间:2014-09-26 19:40:26

标签: sql database oracle

我有这个查询

SELECT 
    PA.PK, PA.PACKAGE_NAME, ATTR.ENGLISH_NAME ATTRIBUTES, 
    PA.VALUE, ATTR_LIST.ENGLISH_NAME ATTRIBUTES_LIST
FROM 
    POSTS_ATTRIBUTES PA 
INNER JOIN 
    POSTS P ON PA.POSTS = P.PK
LEFT OUTER JOIN 
    ATTRIBUTES ATTR ON PA.ATTRIBUTES = ATTR.PK
LEFT OUTER JOIN 
    ATTRIBUTES_LIST ATTR_LIST ON PA.ATTRIBUTES_LIST = ATTR_LIST.PK
WHERE 
    P.FIELDS  = 83;

这给出了像这样的输出

PK | PACKAGE_NAME | ATTRIBUTES            | VALUE  | ATTRIBUTES_LIST 
------------------------------------------------------------------
211| CERAMICS     | RAW MATERIALS         | (null) | CEMENT 
212| CERAMICS     | PRODUCTION OPERATIONS | (null) | PRESSING 
213| CERAMICS     | OPERATIONAL SERVICES  | (null) | FORK LIFTS RENTAL 
214| CERAMICS     | FINISHED PRODUCTS     | (null) | FLOOR CERAMICS

有没有办法通过查询反转列和行,使其看起来像

PACKAGE_NAME | RAW MATERIALS | PRODUCTION OPERATIONS | OPERATIONAL SERVICES | FINISHED PRODUCTS 
---------------------------------------------------------------------------------------------------
CERAMICS     |    CEMENT     |      PRESSING         |   FORK LIFTS RENTAL  |  FLOOR CERAMICS

1 个答案:

答案 0 :(得分:0)

看一下如何转动的this示例。它似乎很好地解释了它。