[ Team LiB ] |
![]() ![]() |
Using Aggregate Functions to Summarize Numeric DataBy using aggregate functions, you can easily summarize numeric data. You can use aggregate functions to calculate the sum, average, count, minimum, maximum, and other types of summary calculations for the data in a query result. These functions let you calculate one value for all the records in a query result or group the calculations as desired. For example, you could determine the total sales for every record in the query result, as shown in Figure 15.26, or you could output the total sales by country and city, as shown in Figure 15.27. You could also calculate the total, average, minimum, and maximum sales amounts for all customers in the United States. The possibilities are endless. Figure 15.26. Total sales for every record in a query result.Figure 15.27. Total sales by country and city.To create an aggregate function, follow these steps:
Figure 15.29 shows the design of a query that finds the total, minimum, maximum, and average sales by country and city; Figure 15.30 shows the results of running the query. As you can see, aggregate functions can give you valuable information. Figure 15.29. A query that finds the total, minimum, maximum, and average sales by country and city.Figure 15.30. The result of running a query that has many aggregate functions.If you save this query and reopen it, you should see that Access has made some changes to its design. Access changes the Total cell for Sum to Expression, and it changes the Field cell to the following: TotalSales: Sum([UnitPrice]*[Quantity]) If you look at the Total cell for Avg, you should see that Access changes it to Expression. Access changes the Field cell to the following: AverageSales: Avg([UnitPrice]*[Quantity]) Access modifies the query in this way when it determines that you're using an aggregate function on an expression that has more than one field. You can enter the expression either way. Access stores and resolves the expression as noted. Task: Building a Query to Summarize and Total Data
As you can see, aggregate functions are both powerful and flexible. You cannot edit their output, but you can use them to view the sum, minimum, maximum, average, and count of the total price, all at the same time. You can easily modify whether you're viewing this information by country, country and city, and so on, all at the click of a mouse. |
[ Team LiB ] |
![]() ![]() |