RATIO_TO_REPORT
functionsupportedCore SQL functionsReturns the ratio of a value within a group to the sum of the values within the group. If expr1 evaluates to null or the sum of expr1 within the group evaluates to 0, then RATIO_TO_REPORT returns null.
Syntax
supportedpartialnot supportednot scored
RATIO_TO_REPORT( <expr1> ) [ OVER ( [ PARTITION BY <expr2> ]
[ ORDER BY <expr3> ] [ { ASC | DESC } ] [ NULLS { FIRST | LAST } ] ) ]
Parameters
| Name | Required | Description |
|---|---|---|
expr1 | required | This is an expression that evaluates to a numeric data type (INTEGER, FLOAT, DECIMAL, etc.). |
expr2 | required | This is the optional expression to partition by. |
expr3 | required | This is the optional expression to order by within each partition. Note that for this function, the order within the partition does not affect the output. In this function, as in all window functions, this ORDER BY does not control the order of the entire query output. |
Usage notes
- RATIO_TO_REPORT is calculated as: value of expr1 argument for the current row / sum of expr1 argument for the partition
- The ORDER BY clause within the OVER clause is allowed in this function for syntactic consistency with other window functions but does not affect the calculation. Snowflake recommends not including the ORDER BY clause when using this function.