A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/sql-reference/functions/var_samp below:

Website Navigation


VAR_SAMP | Snowflake Documentation

Categories:

Aggregate functions (General) , Window function syntax and usage (General)

VAR_SAMP

Returns the sample variance of non-NULL records in a group. If all records inside a group are NULL, a NULL is returned.

Aliases:

VARIANCE , VARIANCE_SAMP

Syntax

Aggregate function

VAR_SAMP( [DISTINCT] <expr1> )

Copy

Window function

VAR_SAMP( <expr1> ) OVER (
                         [ PARTITION BY <expr2> ]
                         [ ORDER BY <expr3> [ ASC | DESC ] [ <window_frame> ] ]
                         )

Copy

For detailed window_frame syntax, see Window function syntax and usage.

Arguments
expr1

The expr1 should evaluate to one of the numeric data types.

expr2

This is the expression to partition by.

expr3

This is the expression to order by within each partition.

Returns

The data type of the returned value is NUMBER(<precision>, <scale>). The scale depends upon the values being processed.

Usage notes Examples

This example shows how to use the VAR_SAMP function:

Create and fill a table:

create table aggr(k int, v decimal(10,2), v2 decimal(10, 2));
insert into aggr values 
   (1, 10, null),
   (2, 10, 11), 
   (2, 20, 22), 
   (2, 25, null), 
   (2, 30, 35);

Copy

Query the table:

SELECT k, var_samp(v), var_samp(v2) 
    FROM aggr 
    GROUP BY k
    ORDER BY k;
+---+---------------+----------------+
| K |   VAR_SAMP(V) |   VAR_SAMP(V2) |
|---+---------------+----------------|
| 1 |          NULL |           NULL |
| 2 | 72.9166666667 | 144.3333333333 |
+---+---------------+----------------+

Copy


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4