SQL CEIL

Rounds UP to the nearest whole number, no matter how small the decimal remainder — 4583.01 becomes 4584.

What & Why

CEIL(n) (short for "ceiling") always rounds up to the next whole number, unless the input is already a whole number. Common use: computing "how many full batches are needed" — 10 items at 3 per batch needs 4 batches, not 3.33.

See How It Works

BUSINESS QUESTION

Marketing wants the minimum whole-thousand budget bucket that can contain each campaign 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,
  CEIL(spend / 1000.0) AS thousand_bucket
FROM marketing.campaigns
ORDER BY campaign_id;
RESULT — exact output from the displayed Queryflo rows
campaign_idspendthousand_bucket
155000.0055
245000.0045
350000.0050
460000.0060

Every displayed spend is already an exact multiple of one thousand.

Now You Try

Practice this concept

Marketing wants the minimum whole-thousand budget bucket that can contain each campaign spend.

Available schema
marketing

Prefix tables with marketing.table_name.

campaign_idspendthousand_bucket
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