SQL Correlation

Does one variable tend to move with another? A single number from -1 to +1 answers that.

What & Why

Correlation measures whether two variables move together. +1 means they move in perfect lockstep upward, -1 means one rises exactly as the other falls, and 0 means no linear relationship at all.

See How It Works

BUSINESS QUESTION

Measure the relationship between email recipients and clicks.

idcampaign_idsent_atrecipientsopensclicksunsubscribesbounces
20112024-01-20 15:00:00+001200540180924
20222024-02-15 16:30:00+0080042096512
20332024-03-18 13:00:00+0015006102251431
20442024-04-08 14:00:00+0000000
EXAMPLE QUERY
SELECT
  CORR(recipients, clicks) AS recipients_clicks_correlation,
  COUNT(*) AS sends
FROM marketing.email_sends
WHERE recipients IS NOT NULL
  AND clicks IS NOT NULL;
RESULT — recipients and clicks
recipients_clicks_correlationsends
0.99269230753882164

The coefficient is calculated from the four representative email-send pairs.

This lesson's practice is part of Pro.

Advanced business practice

Sign up free to try it on a real business scenario