數據透視表提供的數據三維視圖效果,在Microsoft Excel能創建數據透視表,但是,它並不會總是很 方便使用Excel。您可能希望在Web應用程序中創建一個數據透視報表。創建一個簡單的數據透視表可能是 一件非常復雜的任務。所以,我打算不但為你提供一個非常有用的工具創建簡單和高級的數據透視表,而 且為你移除一些籠罩他們的神秘面紗。
目標是:我們想要有能力將datatable中的二維的數據轉換成三維視圖。
在大多數情況下,你會從數據庫的查詢數據填充數據表,例如
SELECt
SalesPeople.FullName AS [Sales Person]
, Products.FullName AS [Product]
, SUM(Sales.SalesAmount) AS [Sale Amount]
, SUM(Sales.Qty) AS [Quantity]
FROM
Sales
JOIN
SalesPeople WITH (NOLOCK)
ON SalesPeople.SalesPersonID = Sales.SalesPersonID
JOIN
Products WITH (NOLOCK)
ON Products.ProductCode = Sales.ProductCode
GROUP BY
SalesPeople.FullName
, Products.FullName
該查詢會產生下面的數據表:
Sales Person Product Quantity Sale Amount John Pens 200 350 John Pencils 400 500 John Notebooks 100 300 John Rulers 50 100 John Calculators 120 1200 John Back Packs 75 1500 Jane Pens 225 393.75 Jane Pencils 335 418.75 Jane Notebooks 200 600 Jane Rulers 75 150 Jane Calculators 80 800 Jane Back Packs 97 1940 Sally Pens 202 353.5 Sally Pencils 303 378.75 Sally Notebooks 198 600 Sally Rulers 98 594 Sally Calculators 80 800 Sally Back Packs 101 2020 Sarah Pens 112 196 Sarah Pencils 245 306.25 Sarah Notebooks 198 594 Sarah Rulers 50 100 Sarah Calculators 66 660 Sarah Back Packs 50 2020