SQL BETWEEN

Checks an inclusive range — both endpoints count as a match.

What & Why

BETWEEN low AND high is shorthand for column >= low AND column <= high — both endpoints are included.

See How It Works

BUSINESS QUESTION

Campaign spend values from 45,000 to 55,000, inclusive.

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
Watch between check each rowRow 1 of 4
-- checking Spring Launch: 55000 between 45000 and 55000?TRUE — kept
namespend
Spring Launch55000
Retention Webinar45000
Finance Retargeting50000
Enterprise Search60000

spend BETWEEN 45000 AND 55000 is true for Spring Launch.

EXAMPLE QUERY
SELECT name, spend FROM marketing.campaigns
WHERE spend BETWEEN 45000 AND 55000;
Now You Try

Practice this concept

Marketing wants email sends from Q2 2024 so lifecycle volume can be reviewed by send date.

Available schema
marketing

Prefix tables with marketing.table_name.

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

Sign up free to try it on a real business scenario