Aggregate Functions

 <  Day Day Up  >  

Another important category of functions are those known as aggregate functions. These include Sum , Count , Min , Max , and Avg . These all work in similar, quite intuitive ways. They each operate on a set of inputs (numeric, except for Count ) and produce a numeric output. The name of the function implies the operation that each performs . Sum adds a set of numbers , Min and Max return the smallest and largest items of a set, Avg returns the arithmetic mean of the numbers, and Count returns the number of non-null values in the set.

The inputs for an aggregate function can come from any one of three sources:

  • A series of delimited values ” For example, Sum(6; 4; 7; 2) yields 19. Average (6; 4; 7; 2) yields 4.75. An interesting use of the Count function is to determine the number of fields in a record into which a user has entered values. For instance, Count (FirstName; LastName; Phone; Address; City; State; Zip) would return 2 if the user had entered values into only those two fields.

  • A repeating field ” Repeating fields enable you to store multiple values within a single field within the same record. For instance, you might have repeating fields within a music collection database for listing the tracks and times of the contents of a given disc. The functions Count(Tracks) and Sum(Times) would produce the number of tracks and the total playing time for a given disc.

  • A related field ” By far, this is the most common application for aggregate functions. Imagine that you have a Customer table and an Invoice table and you want to create a field in Customer that totals up all the invoices for a particular customer. That field would be defined as Sum(Invoices::InvoiceTotal) . Similarly, to tell how many related invoices a customer had, you could use the formula Count(Invoices::CustomerID) .

NOTE

When using the Count function to count related records, it usually doesn't matter what field you count, so long as it's not empty. The count will not include records where the specified field is blank. Typically, you should count either the related primary key or the related foreign key, as these by definition should contain data.


 <  Day Day Up  >  


QUE CORPORATION - Using Filemaker pro X
QUE CORPORATION - Using Filemaker pro X
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 494

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net