SQL Function - Window Aggregate (Analytics function)

1 - About

Windowing functions (known also as analytics) allow to compute cumulative, moving, and centered aggregates.

They are distinguished from ordinary SQL functions by the presence of an OVER clause.

With windowing aggregate functions, you can calculate moving and cumulative versions of SUM, AVERAGE, COUNT, MAX, MIN, and many more functions.

Analytic functions compute an aggregate value based on a group of rows. They differ from aggregate functions in that they return multiple rows for each group. The group of rows is called a window.

Analytic functions enable you to calculate:

Analytic functions can be used in the following areas where standard SQL fails to impress.

  • Ranking data within subsets of a data set.
  • Aggregating data within subsets of a data set.
  • Performing aggregations over moving windows.
  • Displaying and comparing aggregates to individual entries within a single query.
  • Comparing two or more rows within a given data set.
  • Fetching from the translate table the values based on EFFDT.

Partition in the clause statement define the subset.

The data property dense/parse is really important when using this functions.

Analytic functions allow to replace procedural by set based logic.

True streaming platform (not microbatch) will handles late arriving data. The window is never really closed and some late arriving data with a timestamp inside the window can arrive at any time.

3 - The process

Query processing using analytic functions takes place in three stages :

  1. all joins, WHERE, GROUP BY and HAVING clauses are performed.
  2. the result set is made available to the analytic functions, and all their calculations take place.
  3. if the query has an ORDER BY clause at its end, the ORDER BY is processed to allow for precise output ordering.

4 - Functions

List of analytic functions

5 - Reference

data/type/relation/sql/window.txt ยท Last modified: 2018/10/17 21:09 by gerardnico