Query That Summarizes Data

From Apache OpenOffice Wiki
Jump to: navigation, search




Query That Summarizes Data

All the queries we have written so far display all the rows that meet the query criteria. It is very common to want a summary of the data that displays quantities like the sum or the average of a field calculated over some group of rows. For example, we might want the sum of sales for each person. Writing such a query can be done using the Function row of the query definition table in Design View.

Step 1: Start the query in Design View

From the main Base window, click Queries in the left pane and then Create Query in Design View from the Tasks pane.

Step 2: Add tables to the query

In the Add Query or Table dialog, click on People and then the Add button and do the same for the Sales table. Click  Close .

Step 3: Add fields to the query

Double-click on the FirstName and LastName from the People table and Amount from the Sales table to add them to the query definition table.

Step 4: Set the grouping and the sum function

In the Function row of the query definition table, use the drop-down list to set FirstName and LastName to Group and set Amount to Sum. Also set the Alias of the Amount column to Sales_Sum. The final settings of the query definition table are shown in Figure 197.

AOO41GS8 038.png
Figure 197: Query summing Amount for each person
Documentation note.png In a query that uses one or more summarizing functions, also known as aggregating functions, every column must have an entry in the Function row, either as Group or one of the other functions.
Content on this page is licensed under the Creative Common Attribution 3.0 license (CC-BY).
Personal tools