PRODUCT() OVER ...

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

Returns the product of values in the window frame.

Syntax

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

Notes

  • NULL values are ignored; an empty frame gives NULL
  • DuckDB and Trino multiply exactly, for every numeric type
  • Postgres, Snowflake, Databricks, BigQuery, ClickHouse and serving take a DOUBLE or FLOAT only, computed as EXP(SUM(LN(|x|))) with the zeros and the sign counted apart: the last digits can differ from DuckDB. Another type raises UE/WINDOW-PRODUCT-NOT-SUPPORTED-DIALECT; cast the argument with ::DOUBLE

Availability

StatusBackends
Not availablemysql

See also

Examples

FeatureQL
-- Running product to the current row
-- Running product counting only rows where v > 15 (10 and 5 excluded from the frame)
RETURN
    f1 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        RETURN PRODUCT(v) OVER (ORDER BY id ASC)
    ).UNWRAP(),
    f2 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        RETURN PRODUCT(v) FILTER (WHERE v > 15) OVER (ORDER BY id ASC)
    ).UNWRAP()
;
Result
f1 ARRAY<BIGINT>f2 ARRAY<BIGINT>
[30, 300, 6000, 30000][30, 30, 600, 600]