ArticleslgStudy

mathematics

Aggregate function

Aggregate function is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Aggregate function rather than just read about it. In short: In database management, an aggregate function or aggregation function is a function where multiple values are processed together to form a single summary statistic. Common aggregate functions include: Average (i.e., arithmetic mean) Count Maximum Median Minimum Mode Range Sum Others include: Nanmean (mean ignoring NaN values, also known as "nil" or "null") Stddev Formally, an aggregate function takes as input a set…

Aggregate function — main illustration
Aggregate function — illustration

Key takeaways

  • Aggregate function belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Aggregate function to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Aggregate function from memory before moving on to harder problems.

Reference excerpt

In database management, an aggregate function or aggregation function is a function where multiple values are processed together to form a single summary statistic.

Common aggregate functions include:

Average (i.e., arithmetic mean) Count Maximum Median Minimum Mode Range Sum Others include:

Nanmean (mean ignoring NaN values, also known as "nil" or "null") Stddev Formally, an aggregate function takes as input a set, a multiset (bag), or a list from some input domain I and outputs an element of an output domain O. The input and output domains may be the same, such as for SUM, or may be different, such as for COUNT. Aggregate functions occur commonly in numerous programming languages, in spreadsheets, and in relational algebra. The listagg function, as defined in the SQL:2016 standard aggregates data from multiple rows into a single concatenated string. In the entity relationship diagram, aggregation is represented as seen in Figure 1 with a rectangle around the relationship and its entities to indicate that it is being treated as an aggregate entity.

Decomposable aggregate functions Aggregate functions present a bottleneck, because they potentially require having all input values at once. In distributed computing, it is desirable to divide such computations into smaller pieces, and distribute the work, usually computing in parallel, via a divide and conquer algorithm. Some aggregate functions can be computed by computing the aggregate for subsets, and then aggregating these aggregates; examples include COUNT, MAX, MIN, and SUM. In other cases the aggregate can be computed by computing auxiliary numbers for subsets, aggregating these auxiliary numbers, and finally computing the overall number at the end; examples include AVERAGE (tracking sum and count, dividing at the end) and RANGE (tracking max and min, subtracting at the end). In other cases the aggregate cannot be computed without analyzing the entire set at once, though in some cases approximations can be distributed; examples include DISTINCT COUNT (Count-distinct problem), MEDIAN, and MODE. Such functions are called decomposable aggregation functions or decomposable aggregate functions. The simplest may be referred to as self-decomposable aggregation functions, which are defined as those functions f such that there is a merge operator ⁠⋄⁠ such that

f(X⊎Y)=f(X)⋄f(Y) where ⁠⊎⁠ is the union of multisets (see monoid homomorphism). For example, SUM:

SUM⁡(x)=x, for a singleton; SUM⁡(X⊎Y)=SUM⁡(X)+SUM⁡(Y), meaning that merge ⁠⋄⁠ is simply addition. COUNT:

COUNT⁡(x)=1, COUNT⁡(X⊎Y)=COUNT⁡(X)+COUNT⁡(Y). MAX:

MAX⁡(x)=x, MAX⁡(X⊎Y)=max⁡(MAX⁡(X),MAX⁡(Y)). MIN:

MIN⁡(x)=x, MIN⁡(X⊎Y)=min⁡(MIN⁡(X),MIN⁡(Y)). Note that self-decomposable aggregation functions can be combined (formally, taking the product) by applying them separately, so for instance one can compute both the SUM and COUNT at the same time, by tracking two numbers. More generally, one can define a decomposable aggregation function f as one that can be expressed as the composition of a final function g and a self-decomposable aggregation function h, f=g∘h,f(X)=g(h(X)). For example, AVERAGE=SUM/COUNT and RANGE=MAX−MIN. In the MapReduce framework, these steps are known as InitialReduce (value on individual record/singleton set), Combine (binary merge on two aggregations), and FinalReduce (final function on auxiliary values), and moving decomposable aggregation before the Shuffle phase is known as an InitialReduce step, Decomposable aggregation functions are important in online analytical processing (OLAP), as they allow aggregation queries to be computed on the pre-computed results in the OLAP cube, rather than on the base data. For example, it is easy to support COUNT, MAX, MIN, and SUM in OLAP, since these can be computed for each cell of the OLAP cube and then summarized ("rolled up"), but it is difficult to support MEDIAN, as that must be computed for every view separately.

Other decomposable aggregate functions In order to calculate the average and standard deviation from aggregate data, it is necessary to have available for each group: the total of values (Σxi = SUM(x)), the number of values (N=COUNT(x)) and the total of squares of the values (Σxi2=SUM(x2)) of each groups.

AVG: AVG⁡(X⊎Y)=(AVG⁡(X)∗COUNT⁡(X)+AVG⁡(Y)∗COUNT⁡(Y))/(COUNT⁡(X)+COUNT⁡(Y)) or AVG⁡(X⊎Y)=(SUM⁡(X)+SUM⁡(Y))/(COUNT⁡(X)+COUNT⁡(Y)) or, only if COUNT(X)=COUNT(Y) AVG⁡(X⊎Y)=(AVG⁡(X)+AVG⁡(Y))/2

SUM(x2): The sum of squares of the values is important in order to calculate the Standard Deviation of groups SUM⁡(X2⊎Y2)=SUM⁡(X2)+SUM⁡(Y2)

STDDEV: For a finite population with equal probabilities at all points, we have STDDEV⁡(X)=s(x)=1N∑i=1N(xi−x‾)2=1N(∑i=1Nxi2)−(x‾)2=SUM⁡(x2)/COUNT⁡(x)−AVG⁡(x)2 This means that the standard deviation is equal to the square root of the difference between the average of the squares of the values and the square of the average value. STDDEV⁡(X⊎Y)=SUM⁡(X2⊎Y2)/COUNT⁡(X⊎Y)−AVG⁡(X⊎Y)2 STDDEV⁡(X⊎Y)=(SUM⁡(X2)+SUM⁡(Y2))/(COUNT⁡(X)+COUNT⁡(Y))−((SUM⁡(X)+SUM⁡(Y))/(COUNT⁡(X)+COUNT⁡(Y)))2

See also Cross-tabulation a.k.a. Contingency table Data drilling Data mining Data processing Extract, transform, load Fold (higher-order function) Group by (SQL), SQL clause OLAP cube Online analytical processing Pivot table Relational algebra Utility functions on indivisible goods#Aggregates of utility functions XML for Analysis AggregateIQ MapReduce

References

Literature Grabisch, Michel; Marichal, Jean-Luc; Mesiar, Radko; Pap, Endre (2009). Aggregation functions. Encyclopedia of Mathematics and its Applications. Vol. 127. Cambridge: Cambridge University Press. ISBN 978-0-521-51926-7. Zbl 1196.00002. Oracle Aggregate Functions: MAX, MIN, COUNT, SUM, AVG Examples

External links Aggregate Functions (Transact-SQL)

Illustrations

Aggregate function: (Figure 1) Entity relationship diagram representation of aggregation.
(Figure 1) Entity relationship diagram representation of aggregation.

Worked examples

Example 1 — a first encounter with Aggregate function

Start with the simplest possible case. Write down what Aggregate function claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Aggregate function before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Aggregate function ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Aggregate function

In research
Aggregate function appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Aggregate function in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Aggregate function is common in secondary-school and first-year university syllabi. It links to neighbouring topics Subroutines, so understanding it makes those chapters shorter.
In everyday life
Look for Aggregate function outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Aggregate function” →

How to study Aggregate function in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Aggregate function means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Aggregate function out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Aggregate function in simple terms?

In database management, an aggregate function or aggregation function is a function where multiple values are processed together to form a single summary statistic. Common aggregate functions include: Average (i.e., arithmetic mean) Count Maximum Median Minimum Mode Range Sum Others include: Nanmea…

Why does Aggregate function matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Aggregate function?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Aggregate function.

Tags

  • Subroutines

Keep exploring