On this page

    Categories: Aggregate, Window

    COVAR_SAMP

    Returns the sample covariance for non-NULL pairs across all input values.

    Syntax

    COVAR_SAMP(expression1 numeric, expression2 numeric) → double

    • expression1: An expression that evaluates to a numeric type. This parameter is the dependent value.
    • expression2: An expression that evaluates to a numeric type. This parameter is the independent value.

    Examples

    Aggregate function example
    SELECT COVAR_SAMP(trip_distance_mi, fare_amount)
    FROM Samples."samples.dremio.com"."NYC-taxi-trips"
    
    -- 31.70536780565699
    
    Aggregate function example using optional DISTINCT clause
    SELECT COVAR_SAMP(DISTINCT trip_distance_mi, fare_amount)
    FROM Samples."samples.dremio.com"."NYC-taxi-trips"
    
    -- 31.7053678056971
    
    Window function example
    SELECT COVAR_SAMP(trip_distance_mi, fare_amount)
      OVER (PARTITION BY trip_distance_mi)
    FROM Samples."samples.dremio.com"."NYC-taxi-trips"
    
    -- 2.442515362986122e-15
    

    Usage Notes

    This function supports the use of ALL and DISTINCT:

    SELECT COVAR_SAMP( [ { ALL | DISTINCT } ] expression1, expression2)