| ||||||||||||
|
|
|
| New! Download Crosstab/Pivot Query Example Database |
Access provides a pivot query wizard which, once you get some practice you'll find it as good place to start. I usually have to go into the SQL editor and tweak the code a little. Here are the SQL statements that will produce the output we want:
TRANSFORM Sum([M_Sales].[Amount]) AS SumOfAmount
SELECT [M_Sales].[Department]
FROM M_Sales
GROUP BY [M_Sales].[Department]
PIVOT Format([M_Sales].[Sale_date],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
The key points of the query are:
1) The query's TRANSFORM statement contains the values that will be summed and displayed as the results of the query.
2) The SELECT statement will contain the Row Headings
3) The GROUP BY is just what it says 4) The PIVOT statement
will create the column headings and may be thought of as a Horizontal Group
By. Here are the results of the query:
We now offer web-based SQL/Server application development in partnership with Integrated Databases, Inc. (new projects only).
|
|