Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API
Computes the correlation coefficient between two sets of values.
Syntax
corr(<Y>, <X>)
Arguments
Required
<Y>: Adouble precisionexpression representing the dependent variable.<X>: Adouble precisionexpression representing the independent variable.
Returns
Returns a double precision value representing the correlation coefficient, ranging from -1 to 1. Returns NULL if the computation is meaningless (e.g., no valid input pairs).
Considerations
- Returns NULL if there are no rows where both X and Y are non-null.
- A value of 1 indicates perfect positive correlation.
- A value of -1 indicates perfect negative correlation.
- A value of 0 indicates no linear correlation.
Examples
Calculate Correlation
Find the correlation between two variables.
SELECT corr(sales, advertising_spend) AS correlation
FROM marketing_data;
Correlation by Group
Calculate correlation for each category.
SELECT category, corr(revenue, visitors) AS revenue_visitor_corr
FROM store_metrics
GROUP BY category;