|
Unit 8. Summary queries (II) |
|
Grouping records |
|
Until now the summary queries that we have seen use all the rows of the table and produce just one resulting row.
When a grouping field is included, Access forms groups with all the records that have the same value in the grouping field and every group formed this way generates a row in the result of the query, furtharmore, the defined calculations are carried out on the records of every group. In this way Subtotals can be obtained E.g if we want to know how many customers we have in each state we need to indicate that we want to count the records of the Customers table but firstly grouping them by the State field. In this way the count() function will calculate on every group of records (clients of the same state). The query will remain like this:
The memo and OLE type fields can not be defined as grouping field.
|
|
It can only contain field names with an aggregate function (the functions we just looked at (sum( ), Avg( ), StDev( ), Min( ), Max( )...), fixed values or names of columns that appear with the Group by option. An expression can combine various aggregate functions,
but it is not possible to nest aggregate functions,
e.g an expression could be Max(hours)-Min(hours) but not
Max(sum(hours)). |
|
For the search criteria, the same operators as in a normal query can be used, multiple conditions can also be written (joined by the Or, AND,NOT operators). E.g we want to know how many customers we have in California, for this we need to count the records from the Customers table but previousely selecting those from California (State="CA"), this is defined in the following way:
For the selection condition the same operators as in a normal query can be used, multiple conditions can also be written (joined by the Or, AND,NOT operators), a limitation exists in the Criteria: row, the name of a column can not be put down if this column is not a grouping field.
|
|
|
|
|
| |
|
Page. 8.2 |
|
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.
|