1
問:如何將數據錶轉換爲類似ReportingService的矩陣?
我有我從一個數據庫,它看起來像這樣檢索數據:
現在我需要將其轉換爲下面的格式,以能夠畫一個餅圖。
在ReportingService,有矩陣控制來實現這一點,但我可以用它來實現普通的C#一樣,爲了使它對一個餅圖的形象?
請注意,建築物數量以及使用類型是可變的,並且不會提前知道。
編輯:
解決由於馬格努斯和谷歌:
SELECT * FROM
(
SELECT
STE_Designation AS RPT_Site
,BDG_Designation AS RPT_Building
,UG_Code AS RPT_Usage_Code
,UG_Caption AS RPT_Usage
,SUM(MP_RMArea_Area) AS RPT_Area
FROM V_RPT_RoomDetail
WHERE (RM_MDT_ID = 1)
GROUP BY
STE_Designation
,BDG_Designation
,UG_Code
,UG_Caption
--ORDER BY STE_Designation, BDG_Designation, UG_Code, UG_Caption
) AS SourceTable
PIVOT
(
SUM(RPT_Area)
FOR RPT_Building IN ([Building1], [Building2], [BuildingN])
) AS PivotTable
ORDER BY RPT_Site, RPT_Usage_Code
凡樞軸列需要由SELECT DISTINCT在代碼中產生。