Learn SQL/Intermediate/Numeric Functions/SQL Mathematical Operators

SQL Mathematical Operators

The final Intermediate-tier series — basic arithmetic and the percentage/growth-rate calculations that show up in nearly every business report.

What & Why

This closing series of the Intermediate tier covers the numeric side of SQL: the five arithmetic operators (+, -, *, /, %), common single-value functions (ABS, ROUND, CEIL, FLOOR, POWER, SQRT, MOD), and the percentage-based calculations — percent-of-total, percent-change, growth rate — that appear in almost every real business report.

See How It Works

BUSINESS QUESTION

Marketing wants each campaign's 10% buffer and unrounded planned spend.

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,
  spend * 0.10 AS buffer_amount,
  spend + (spend * 0.10) AS planned_spend
FROM marketing.campaigns
ORDER BY planned_spend DESC;
RESULT — exact output from the displayed Queryflo rows
campaign_idspendbuffer_amountplanned_spend
460000.006000.000066000.0000
155000.005500.000060500.0000
350000.005000.000055000.0000
245000.004500.000049500.0000

Multiplication creates the ten-percent buffer before addition creates planned spend.

Now You Try

Practice this concept

Marketing wants the unrounded ten-percent buffer and planned spend for each campaign.

Available schema
marketing

Prefix tables with marketing.table_name.

campaign_idspendbuffer_amountplanned_spend
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