Session 5 - Aggregate Functions, spatial aggregates Flashcards
List all window Functions
CUME_DIST DENSE_RANK FIRST_VALUE LAG LAST_VALUE LEAD NTILE PERCENT_RANK RANK ROW_NUMBER
CUME_DIST Function
Calculate the cumulative distribution of a value in a set of values
DENSE_RANK Function
Assign a rank value to each row within a partition of a result, with no gaps in rank values.
FIRST_VALUE Function
Get the value of the first row in an ordered partition of a result set.
LAG Function
Provide access to a row at a given physical offset that comes before the current row.
LAST_VALUE Function
Get the value of the last row in an ordered partition of a result set.
LEAD Function
Provide access to a row at a given physical offset that follows the current row.
NTILE Function
Distribute rows of an ordered partition into a number of groups or buckets
PERCENT_RANK Function
Calculate the percent rank of a value in a set of values.
RANK Function
Assign a rank value to each row within a partition of a result set
ROW_NUMBER Function
Assign a unique sequential integer to rows within a partition of a result set, the first row starts from 1.
Aggregate Over Syntax
AGGREGATE() OVER (PARTITION BY COLUMN1, COLUMN2 ORDER BY COLUMN1, COLUMN2 DESC)
what happens to the total when you have an order by and a sum (pertaining to Over clause)
the total is incremented
What is the syntax using ROWS in Over Clause
ROWS BETWEEN [NUMBER] PRECEDING AND [NUMBER] FOLLOWING
UNBOUNDED AND CURRENT ROW (Instead of Preceding or Following) Can also be used instead of number
What is the syntax using RANGE in Over Clause
RANGE BETWEEN [UNBOUNDED or CURRENT ROW or 0] PRECEDING AND [UNBOUNDED or CURRENT ROW or 0] FOLLOWING
Which is more efficient, ROW or RANGE?
ROW. Range has to worry about ties and is overall slower
What is required with ROW and RANGE
ORDER BY.
What is default when using OVER (Regarding ROWS and RANGE) Without ORDER BY? With ORDER BY?
RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING IS DEFAULT
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW IS DEFAULT WHERE THERE IS ORDER BY
What do ROW_NUMBER(), RANK(), DENSE_RANK() OVER () require?
ORDER BY