SQL CORR

The function that computes the actual correlation coefficient from the previous lesson.

What & Why

CORR(y, x) computes the Pearson correlation coefficient between two numeric columns — the exact -1-to-+1 number the previous lesson described.

See How It Works

BUSINESS QUESTION

Marketing wants the correlation between email opens 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
  ROUND(CORR(opens, clicks)::numeric, 4) AS opens_clicks_correlation
FROM marketing.email_sends;
RESULT — opens and clicks
opens_clicks_correlation
0.9615

The rounded coefficient uses the four real email-send rows.

This lesson's practice is part of Pro.

Advanced business practice

Sign up free to try it on a real business scenario