Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
In this course, author Adam Wilbert illustrates how to create and leverage real-world queries and turn raw data into usable information. The course covers setting up queries, performing calculations, using the built-in Access functions to further refine query results, and identifying top performers or areas for improvement based on a range of criteria.
Access databases are really good at collecting and storing large amounts of raw data. Most of the time you want to summarize or aggregate data points together to get a better understanding of some of the trends or rankings that might otherwise be buried within all that data. We can create that query by going to Create tab and then Query Design. Let's add our DirectCustomers table and close this window. Let's add a couple of fields here, FirstName and LastName, and we'll run this query.
We'll see that Access after brief calculation returns a thousand records. This is the number of customers that we have in our database. We can verify that by going into Chapter 1 and taking a look at the DirectCustomers table. I'll open this and we'll see that we have the same thousand records. Go ahead and close this down. I'll go back to our Design view in the Query. Let's add another table. I'll right-click and say Show Table. Let's add our Orders table. We'll close the Show Table window and we'll add OrderID.
If I run the query now, Access going to returned 2200 records. This is the number of transactions that we have in our database, and we can verify that by taking a look at our Orders table. I open that up. We'll see the same value, 2200 records. Okay, let's close that out. So when you add fields to your query, access expands the data table to accommodate all of the data. We have multiple customers in our database that have placed multiple orders. We can see that by looking at the OrderID and we have first and last name repeated several times.
So Access takes our query results and expands them to accommodate the most transactions. We have 2200 transactions and you can see that some customers are repeated multiple times. Let's go back in our Design view and take advantage of this. We can go ahead and remove the OrderID. So you can move our cursor to the very top here. We can right-click and say Cut. Let's add another table to our query. Right-click, Show Table, an let's add our Products table. From here we can get the total price that each customer has spent.
We'll close this out and add Price to our query. Let's run this query again. We will see that we have the same 2200 records that represents the number of transactions in our database. Back to Design view. Let's go ahead and turn on our totals row, using this button up here on the ribbon. When we activate that you'll notice a new row here and all of these fields get a Group By clause. Let's see what happens when we run the query now. We'll see that number has diminished from 2200 to 2152.
So what does that mean? That means that there are a couple of records in here where we have several customers that have placed probably the same order multiple times. So we have fields where the first name, the last name, and the price were all the same. By turning On the Totals column, Access grouped those values together into a single record. Let's go back in our Design view. Now we could take advantage of this grouping level by using a dropdown menu on this Group By field. If I click here under Price we'll see that we have multiple options for summary calculations.
Instead of just grouping those values together we can add them up using the Sum function. Let's click on Sum and we'll say Run. Now we can see that we're down to 894 records. This is the number of customers that have actually placed orders. The sum total of all of their orders is represented in this third column. We can sort it by clicking on this drop-down menu and say Largest to Smallest and we can see that Sebastian Rich over the lifetime of our database has spent the most money with the Two Trees Olive Oil Company. He spent $260.24.
Let's go back into Design view and add a few more fields. We'll add another column for Price. We will change this group by, instead of Group By, we'll turn this to Average. Let's add one more column for Price. We'll change this one to Count. Okay, so now we've got a query that'll give us the first name of our customer, the last name of our customer, a sum total of all of their transactions, the average value for the transaction, and the number of transactions that they have placed with the company.
We will run this query and we get to see multiple results. Let's expand this average out so we get the full data and let's go ahead and sort by SumOfPrice again, Largest to Smallest. So Sebastian Rich who spent $260 with the company usually spends about $43 every transaction and he has placed a total of six transactions with the company. When building your database it's always best to keep your data broken into the smallest piece as possible. For instance by having sales figures for each day, you can use aggregation functions to derive the monthly, quarterly, or yearly numbers without needing to have separate tables for month, quarter, or year.
By keeping the data points discrete and using queries to combine the sales figures as needed you'll keep your database as flexible and it will answer any questions that you might like to throw at it. Aggregate operations will give you the answers to some of the most common questions that you might have about your data. They provide the mechanism for all kinds of summaries, trend analysis, or rankings. They're great way to move beyond simply reviewing your data to understanding what it actually means.
There are currently no FAQs about Access 2010: Queries in Depth.
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.