![]() |
Tables & Queries: |
![]() Did you want: Working with Databases: Access 2007, 2010, 2013, 2016 | ||||
|
![]() |
A crosstab
query
Example: Averages A datasheet of score averages is a crosstab, like the one below from the LanguageArtsClasses database. Students with their ID numbers are listed down the left (2 sets of row headings) and the subjects are across the top (column headings). The value in the cell is the average of the scores that student (row) made on assignments in that subject/type (column). If there is only 1 score per assignment, the "average" winds up being just the plain score. (How tricky!)
A similar crosstab could average the term grade for a subject. |
![]() |
Project 3: Tables & Queries
| |||||||||||||
Example: Crosstab Query - Count with row totalsTo distribute camp t-shirts on the first day of a summer day camp you need a stack of t-shirts for each unit. How many of each size do you need for each unit of campers? In this example, (based on a real day camp) there are 12 units, 4 sizes for Adult-sized t-shirts and 4 sizes for Child-sized t-shirts. This could be messy! A crosstab datasheet is a very useful way to display this information. Rows: The combinations of unit and t-shirt type (Adult or Child sizing) are listed down the left (row headings). Each unit needs at least 2 rows, one for the Adult sizes and one for Child sizes. A third row appears if there is a record that does not list a t-shirt size. Columns: The sizes are across the top (column headings). The column <> is for records that do not have a value for the t-shirt size. (Whoops!) This crosstab query also includes a Total for each row, Total Of ID. Very useful when counting out the stacks. The sizes across the top and the units down the side are in alphabetical order. To sort columns in order by increasing or decreasing size we would need another table that ordered these sizes and set up a relationship. Cells: The value in a cell is the Count of t-shirts needed of that size (column) for that t-shirt type (row) and camp unit (row).
Examine the 3 rows for the unit J1. This unit needs both Adult size t-shirts and Child sizes. One record in J1 does not have a t-shirt size entered (Column <>).
Crosstab Query WizardAccess tries to make creating a crosstab query easy. The wizard walks you through the choices that you must make. You must pick one or more fields for row headings and one field for column headings. You must pick a field to use for the value in the cell, which is a calculation like a SUM or COUNT. Let's look at the steps to create the T-shirts_Crosstab query shown above.
|
![]() |
Step-by-Step: Crosstab Query |
![]() |
What you will learn: |
to use the Crosstab Query Wizard |
Start with:
,
Projects
database open.
The tables in the Projects database are clearly not complete. You will, however, construct a crosstab query that will help when there are many more records in the tables. Your crosstab query will count the number of people with a particular Title for each Country/Region.
Switch, if necessary, to the Database
Window.
Click
on the New Objects button and select New Query.
The New Query dialog opens.
Select Crosstab Query Wizard and click
on OK.
The wizard opens.
Step
1 - Source:
Select the table Staff.
Click Next.
Step
2 - Row heading(s):
Select Country/Region
and click the > button to move the field to the Selected Fields
list.
Click Next.
Step
3 - Column heading:
Select Title.
Click Next.
Step
4 - Value:
Select Count.
Click Next.
Step
5 - name:
Type Staff_Crosstab.
Click on Modify the design.
Click Finish.
The query is automatically saved.
The
wizard closes and the query opens in Query Design view.
Run the query.
The column Total of EmployeeID is a sum for the row, the number of
employees in each country. The other columns count the number of
employees with that title in that country.
Exchanging the row and column choices in the wizard would give you the
number of employees for each job title.
Close the query. (It is already saved.)
![]() |
~~ 1 Cor. 10:31 ...whatever you do, do it all for the glory of God. ~~ |