VAR_SAMP() OVER ...

All functions > WINDOW FUNCTION > VAR_SAMP() OVER ...

Returns the sample variance over the window frame.

Syntax

VAR_SAMP(expr) [FILTER (WHERE condition) | WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])

Notes

  • Computes sample variance (divides by N-1) over a window of rows
  • NULL values are ignored in the calculation

See also

Examples

FeatureQL
SELECT
    -- Sample variance of v in the frame (id is only the sort key)
    f1 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        SELECT VAR_SAMP(CAST(v AS DOUBLE)) OVER (ORDER BY id ASC).ROUND(2)
    ).UNWRAP(),
    -- Sample variance counting only rows where v > 15 (10 and 5 excluded from the frame)
    f2 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        SELECT VAR_SAMP(CAST(v AS DOUBLE)) FILTER (WHERE v > 15) OVER (ORDER BY id ASC).ROUND(
            2
        )
    ).UNWRAP()
;
Result
f1 ARRAYf2 ARRAY
[null, 200.00, 100.00, 122.92][null, null, 50.00, 50.00]

Last update at: 2026/06/20 10:08:10