SQL POWER

Raises a number to an exponent — POWER(base, exponent) — used for compound growth calculations and exact squaring/cubing.

What & Why

POWER(base, exponent) computes base raised to exponent. Beyond simple squaring, this is the building block for compound growth formulas — projecting a value forward across multiple periods of the same growth rate.

See How It Works

BUSINESS QUESTION

Marketing wants the squared and square-root transformations of campaign spend for a modeling export.

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
  id AS campaign_id,
  spend,
  ROUND(POWER(spend, 2), 2) AS spend_squared,
  ROUND(SQRT(spend), 2) AS spend_root
FROM marketing.campaigns
ORDER BY campaign_id;
RESULT — exact output from the displayed Queryflo rows
campaign_idspendspend_squaredspend_root
155000.003025000000.00234.52
245000.002025000000.00212.13
350000.002500000000.00223.61
460000.003600000000.00244.95

Both transformations are rounded to two decimals in the displayed query.

Now You Try

Practice this concept

Return every campaign spend, its square, and its square root rounded to two decimals, ordered by campaign id.

Available schema
marketing

Prefix tables with marketing.table_name.

campaign_idspendspend_squaredspend_root
marketing.campaigns
ColumnType
idinteger
nametext
channeltext
spendnumeric
start_datedate
end_datedate
statustext
target_segmenttext
legacy_idtext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario