假设我们有原始 [SalesData]
SalesYear SalesMonth Region SalesTotal
--------- ---------- ------ ----------
2010 11 East 45
2010 11 West 58
2010 12 East 55
2010 12 West 63
2011 1 East 51
2011 1 West 54
2011 2 East 55
2011 2 West 61
我们可以创建一个 [SalesTotals] 查询来将月销售总额与年度总额相结合......
SELECT SalesYear & "-" & Format(SalesMonth, "00") AS SalesPeriod, Region, SalesTotal FROM SalesData
UNION ALL
SELECT SalesYear & "-Total", Region, SUM(SalesTotal) FROM SalesData GROUP BY SalesYear, Region;
...产生
SalesPeriod Region SalesTotal
----------- ------ ----------
2010-11 East 45
2010-11 West 58
2010-12 East 55
2010-12 West 63
2011-01 East 51
2011-01 West 54
2011-02 East 55
2011-02 West 61
2010-Total East 100
2010-Total West 121
2011-Total East 106
2011-Total West 115
然后我们可以对 [SalesTotals] 查询进行交叉表查询...
TRANSFORM Sum(SalesTotals.[SalesTotal]) AS SumOfSalesTotal
SELECT SalesTotals.[Region]
FROM SalesTotals
GROUP BY SalesTotals.[Region]
PIVOT SalesTotals.[SalesPeriod];
...产生
Region 2010-11 2010-12 2010-Total 2011-01 2011-02 2011-Total
------ ------- ------- ---------- ------- ------- ----------
East 45 55 100 51 55 106
West 58 63 121 54 61 115