Syntax
Parameters
Parameter | Description | Supported input types |
---|---|---|
<value> | A value used for the AVG() function | Any numeric type |
<partition_by | An expression used for the PARTITION BY clause | Any |
Return Types
NUMERIC
if the input is typeINTEGER
,BIGINT
orNUMERIC
DOUBLE PRECISION
if the input is typeREAL
orDOUBLE PRECISION
Example
The example below is querying test scores for players in various game levels. Unlike a regularAVG()
aggregation, the window function allows us to see how each student individually compares to the average test score for their game level.
nickname | level | currentscore | score_average |
---|---|---|---|
kennethpark | 9 | 76 | 75.77777 |
sabrina21 | 7 | 90 | 81.33333 |
burchdenise | 8 | 79 | 79.55555 |
ymatthews | 6 | 85 | 93.88888 |
rileyjon | 8 | 80 | 84.99999 |