中文网站
  Advanced Search
Read the latest Blogs from IT professionals in the field. Read and write community created documents. Need IT help? Ask our staff. Connect with your peers. Check our Tech Shop for posters, books and software tools. Home

3.5.3 Database Systems: Aggregate functions

1. Aggregate functions: sum, avg, count, min, max.

2. The collections on which aggregate functions are applied can have multiple occurrences of a value: the order in which the value appears is irrelevant. Such collections are called multisets. For example,

sumsalary(pt_works):

3. To eliminate multiple occurrences of a value prior to computing an aggregate function, with the addition of the hyphenated string disinct appended to the end of the function name. For example,

count_distinctbname(pt_works):

4. Grouping and then aggregating: To find the total salary sum of all part-time employees at each branch (not the entire bank!),

bnamecount-distinctsalary(pt_works):

5. The general form of the aggregation operation G is as follows.

G1,G2,...,GnG F1A1,F2A2,...,FmAm(E)

where E is any relational-algebra expression, G1,G2,...,Gn constitute a list of attributes on which to group,each Fi is an aggregate functions, and each Ai is an attribute name.

The meaning of the operation:

  • The tuples in result of expression E is partitioned into groups. All tuples in a group has the same values
    for G1,G2,...,Gn, and tuples in di erent group have different values.
  • For each group (g1, g2,...,gn), the result has a tuple (g1, g2,...,gn, a1,a2,...,am) where, for each i,ai is the result of applying the aggregate function Fi on the multiset of values for attribute Ai in the group.

6. Example. Find sum and max of salary for part-time employees at each branch.

bnameGsumsalary,maxsalary(pt_works),

Database System Structure: