SQL ROUND

Rounds a decimal number to a specified number of decimal places — the standard way to clean up a long, ugly fraction for display.

What & Why

ROUND(n, decimals) rounds to the given number of decimal places. Omitting the second argument rounds to the nearest whole number.

See How It Works

BUSINESS QUESTION

Marketing wants click rates rounded to two decimals and recipient estimates rounded in both directions.

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
  id AS send_id,
  ROUND(clicks::numeric / NULLIF(recipients, 0) * 100, 2) AS click_rate_pct,
  CEIL(recipients * 0.10) AS audience_ceiling,
  FLOOR(recipients * 0.10) AS audience_floor
FROM marketing.email_sends
ORDER BY send_id;
RESULT — exact output from the displayed Queryflo rows
send_idclick_rate_pctaudience_ceilingaudience_floor
20115.00120120
20212.008080
20315.00150150
204NULL00

ROUND, CEIL, and FLOOR operate on the displayed email-send values.

Now You Try

Practice this concept

Marketing wants click rate rounded to two decimals and ten-percent audience estimates rounded upward and downward.

Available schema
marketing

Prefix tables with marketing.table_name.

send_idclick_rate_pctaudience_ceilingaudience_floor
marketing.email_sends
ColumnType
idinteger
campaign_idinteger
sent_attimestamp with time zone
recipientsinteger
opensinteger
clicksinteger
unsubscribesinteger
bouncesinteger
legacy_send_grouptext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario