lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

aggregations.md (958B)


      1 +++
      2 title = "Aggregations"
      3 +++
      4 
      5 # Aggregations
      6 
      7 A view declaration registers a query (not the result) under an
      8 identifier
      9 
     10 Simple aggregation functions: COUNT, SUM, AVG, MAX, MIN
     11 
     12 Restrictions:
     13 
     14 -   aggregations can\'t be nested
     15 -   aggregations can\'t be used in the `WHERE` clause
     16 -   if aggregation function is used, and there\'s no `GROUP BY`,
     17     attributes can\'t appear in the `SELECT`
     18 
     19 Null values and aggregations
     20 
     21 -   usually, they\'re ignored before the aggregation
     22 -   `COUNT(*)` counts null values. it counts rows, not attribute values
     23 
     24 GROUP BY partitions tuples of a table into groups, based on value
     25 equality for the GROUP BY attributes. It can never produce empty groups.
     26 Aggregation functions are applied to groups separately. Sequence of
     27 GROUP BY is not important.
     28 
     29 `HAVING` is a way to filter out groups based on some property. E.g.
     30 `HAVING SUM(POINTS) >= 18`. `HAVING` should *only* contain aggregation
     31 functions, not single attributes.