Updated on 2026-11-06 GMT+08:00

corr

Function

The corr function is used to return the correlation coefficient of two numeric columns.

Syntax

corr(col1, col2)

Parameters

Parameter

Mandatory

Type

Description

col1

Yes

DOUBLE, BIGINT, INT, SMALLINT, TINYINT, FLOAT, or DECIMAL

A column with numeric data type. Other types return NULL.

col2

Yes

DOUBLE, BIGINT, INT, SMALLINT, TINYINT, FLOAT, or DECIMAL

A column with numeric data type. Other types return NULL.

Return Values

Returns a value of type DOUBLE.

Examples

  • Calculate the correlation coefficient between all items inventory and price. Example command:
    select corr(items,price) from warehouse; 

    Result:

    _c0         
    1.242355   
  • Used with GROUP BY to group all items by warehouse (warehouseId) and calculate the correlation coefficient between items inventory and price within the same group. Example command:
    select warehouseId, corr(items,price) from warehouse group by warehouseId; 

    Result:

    warehouseId _c1         
    city1   0.43124    
    city2   0.53344    
    city3   0.73425