SQL Variance

Standard deviation, before the square root — the same spread, in squared units.

What & Why

Variance is standard deviation squared. It's the same underlying calculation — STDDEV just takes the square root at the end to bring the units back to something directly comparable to the original data (dollars, not dollars-squared).

See How It Works

BUSINESS QUESTION

Compare campaign-spend variance across channels.

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
SELECT
  channel,
  COUNT(*) AS campaigns,
  ROUND(VAR_SAMP(spend), 2) AS sample_variance_spend
FROM marketing.campaigns
GROUP BY channel
ORDER BY sample_variance_spend DESC NULLS LAST, channel;
RESULT — sample spend variance
channelcampaignssample_variance_spend
google_ads212500000.00
email1NULL
linkedin1NULL

Only the two-row google_ads group has a defined sample variance.

This lesson's practice is part of Pro.

Advanced business practice

Sign up free to try it on a real business scenario