Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
All of the queries that we've been working with throughout this course have been examples of select queries, basically queries that select and manipulate data from our tables and present the results in a new but temporary table format. But Access also has a couple of other query types that we can work with. The first type is called Crosstab query. Like the Select queries, the Crosstab query pulls information from our tables and reorganizes it. But unlike a Select query, the Crosstab query is presented more like a standard spreadsheet with column headers and row headers.
Right now, I've got opened on the screen qry_ AverageWageCrosstab from my Chapter 8 section. We've got three columns here on the left. I've got states, the number of employees in each state, and the average hourly rate of pay for the employees in each state. After that, I've got some column headings here for each department and we can see the average rate of pay within each department for those states. And we scroll across here and we can see that for the sales department in Alaska the average hourly rate is $16.21.
Let's switch into Design view to see how this is built. I'll go to the Home ribbon and click on Design view. You can see the Crosstab query has a new row here and we've selected which are the row headings, for instance the State, the # of Employees, and the Average Hourly Rate are row headings. You also have a column heading for departments across the top and the values in the center are the average of the hourly pay for each employee. So that's how this Crosstab was created. Let's take a look at another example.
I'll go ahead and open up my qry_Crosstab query. Currently, this query is presented as a simple Select query with columns. We've got a CountOfProducts here and then the Size and Oil Name for those products. This table is giving us the popularity of each of our products or how many times each product has been ordered. In order to facilitate analysis, let's change this to a Crosstab query. I'll go to my Design view and I'll turn on my Crosstab query option. You can see that when we do that, we've got a new row here called Crosstab, and some blank fields.
If we click in each field, we'll see that it's a drop-down and we can choose a Row Heading, Column Heading, or Value for each of our fields. For the ProductID, we'll choose Value. The count of the products is what's going to appear in the center of the crosstab. We'll have the size running along the top, as our column header. The oil name will run down the left side as our row header. Let's go ahead and take a look and see how this runs now. We'll run the query and we'll see that the data is presented in a completely different way. We've got the oil names on the left, the sizes across the top, and the count of the number of times each product has been ordered fills the middle.
So depending on the types of information that you're collecting, the Crosstab query could be a great way to visualize large amounts of aggregated data and provide further insight into your database.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.