透视和合并来自sql查询的数据

| 这是我的查询:
SELECT  ad.Name, av.Value AS Attribute1, ctv.Value AS Attribute2
FROM    AttributeDefinitions AS ad WITH (nolock) 
INNER JOIN AttributeValues AS av WITH (nolock) 
ON      ad.AttributeDefinitionID = av.AttributeDefinitionID 
INNER JOIN AttributeCategories 
ON      ad.AttributeCategoryID = AttributeCategories.AttributeCategoryID 
LEFT OUTER JOIN CodeTableValues AS ctv WITH (nolock) 
ON      av.CodeTableValueID = ctv.CodeTableValueID
WHERE   (AttributeCategories.Name = \'Camp\') AND (av.AttributeValueGroupID = 9840)
我的结果看起来像这样:
Name                     Attribute1      Attribute2
Childs Age:              10 
Attended Camp Before?:   Yes
Childs T-Shirt Size:     large           NULL
Allergies Description    none            NULL
Phone #                  212-555-1212    NULL
Pickup                   Mary Jordan     NULL

Name= Name of Attribute Column
Attribute1 = Data is from a free Form
Attribute2 = Data is from a Drop down Menu   
我想做的是旋转数据,以便“名称”列中的信息成为列标题,我需要合并属性1和2中的值 这是我的结果应为:
*Childs Age  Attended Camp Before?  Childs T-Shirt Size  Allergies Description Phone#        Pickup*
10           yes                    large                none                  212-555-1212  Mary Jordan
    
已邀请:
        在Oracle DB中,我使用CASE语句将行转换为列。 看一下这个例子: 选择event_date       ,sum(当service_type = \'OCSAC_DEG \'然后service_count结束的情况)ocsac_deg       ,sum(当service_type = \'SMS_ONL \'则service_count结束的情况)sms_onl       ,sum(当service_type = \'SMS_DEG \'则service_count结束的情况)sms_deg       ,sum(当service_type = \'DATA_ONL \'则service_count结束的情况)data_onl       ,sum(当service_type = \'DATA_DEG \'然后service_count结束的情况)data_deg  来自STATS 其中to_char(event_date,\'yyyymm \')= to_char(add_months(sysdate,-1),\'yyyymm \') 按event_date分组 按event_date desc排序     

要回复问题请先登录注册