2013-07-03 174 views
2

通過運行以下查詢我會得到下面的結果。我想將這個結果轉換爲行,以及將那些我想要轉換爲列的行作爲行。行到列,反之亦然轉換

我希望project_level和account_level進入行,剩下的行進入列。

SELECT S.Description,T.Project_Level,S.Account_Level FROM 
(   
    SELECT DISTINCT SM.Description, COUNT(VA.FK_Status_ID) AS Project_Level,SM.Seq 
        From DeliveryPlatform_APPS.VA.DP_VA_Item_Status_Master SM 
        LEFT OUTER JOIN DeliveryPlatform_APPS.VA.DP_VA_Items VA ON SM.Status_ID = VA.FK_Status_ID 
        AND VA.FK_DP_Entity_Type_ID = 1 AND FK_DP_Entities=671 
        GROUP BY SM.Description,SM.Seq,FK_Status_ID   
) AS T    
INNER JOIN   
(   
    SELECT DISTINCT SM.Description, COUNT(VA.FK_Status_ID) AS Account_Level,SM.Seq 
        From DeliveryPlatform_APPS.VA.DP_VA_Item_Status_Master SM 
        LEFT OUTER JOIN DeliveryPlatform_APPS.VA.DP_VA_Items VA ON SM.Status_ID = VA.FK_Status_ID 
        AND VA.FK_DP_Entity_Type_ID = 1 AND FK_DP_Entities=671 
        GROUP BY SM.Description,SM.Seq,FK_Status_ID   
) AS S 
ON S.Description=T.Description 
--ORDER BY Seq 

Description  Project_Level  Account_Level 

Accepted   0     0 
Closed   0     0 
Delivered   0     0 
Dropped   0     0 
Open    0     0 
Parked   0     0 
Shortlisted  0     0 
Work In Progress 0     0 

回答