|
Unit 8. Summary queries (I) |
|
Definition |
|
In Access we can define a special query to calculate totals on the records of a table (or various tables related). In order to obtain those totals we use summary functions so it is why we call them summary queries. It is important to remember that the resulting rows of a summary query have a distinct nature to the rest of the rows resulting from queries as each row corresponds to various rows in the source table. A 'non summary' query row corresponds to a row in the source table and contains data found in just one row of the source, whilst a row from a summary query corresponds to the summary of various rows from the source table, this difference is the origin of a series of restrictions that the summary queries suffer as we will see later. For example, this type of query does not permit us to edit the data. In the next image we have an example of a normal query in which one visualizes the rows of a table of offices sorted by area, in this case every row of the result corresponds to just one row in the offices table, while the second query is a summary query, every row of the result corresponds to one or various rows in the offices table.
|
|
|
|
We create a summary query by selecting the Totals
option in the View menu or by clicking on the In either case a row is added to the QBE grid, the Total: row. All the columns that we include in the grid should have a value in this row, this value indicates to Access what to do with the values contained in the field written in the Field: row. The values that we can indicate in the Total: row are those that appear in the drop down list associated with this cell as we see in the image to the right. |
|
The summary functions are functions that allow us to obtain a result based on the values contained in one column of a table and they can only be used in a summary query. To use these functions we can write them directly in the Field: row of the grid as we will see ahead, but we can also use a simpler method which is selecting from Total: row in the grid the option corresponding the function. Next we will describe these options. |
|
|
|
It is interesting to distinguish that the null value is not the equivalent of 0, the summary functions do not consider null values while they consider the 0 value as a value, therefore in the average and the standard deviation the results will not be the same with 0 values as with null values.
In order for the number of records to be counted the Count(*) function needs to be used, it returns the number of rows and therefore also counts the null values. In this case we need to select the Expression option and write it like this:
|
|
To continue with this unit go to the next page...
|
| | | Page. 8.1 |
|
Legal warning: Authorised on-line use only. It is not allowed the use of these courses in companies or private teaching centres.
|
|
© aulaClic. All rights reserved. Reproduction in any form whatsoever is prohibited.
April-2006.
|