SQL Subtraction

The - operator subtracts one numeric value from another — order matters, unlike addition.

What & Why

Plain - subtracts the right-hand value from the left-hand one. Unlike addition, order genuinely matters here — a - b and b - a give opposite-signed results.

See How It Works

BUSINESS QUESTION

Marketing wants unopened-recipient counts for each email send.

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,
  recipients - opens AS unopened_recipients
FROM marketing.email_sends
ORDER BY send_id;
RESULT — exact output from the displayed Queryflo rows
send_idunopened_recipients
201660
202380
203890
2040

Recipients minus opens yields the displayed unopened counts.

Now You Try

Practice this concept

Marketing wants unopened-recipient counts for each email send.

Available schema
marketing

Prefix tables with marketing.table_name.

send_idunopened_recipients
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