SQL Addition
The + operator adds two numeric values together — works on literals, columns, or any combination of both.
What & Why
Plain + adds two numbers. It works between two columns, a column and a literal, or two literals — the same operator in every case.
See How It Works
BUSINESS QUESTION
Marketing wants total engagement from opens and clicks for each email send.
| id | campaign_id | sent_at | recipients | opens | clicks | unsubscribes | bounces |
|---|---|---|---|---|---|---|---|
| 201 | 1 | 2024-01-20 15:00:00+00 | 1200 | 540 | 180 | 9 | 24 |
| 202 | 2 | 2024-02-15 16:30:00+00 | 800 | 420 | 96 | 5 | 12 |
| 203 | 3 | 2024-03-18 13:00:00+00 | 1500 | 610 | 225 | 14 | 31 |
| 204 | 4 | 2024-04-08 14:00:00+00 | 0 | 0 | 0 | 0 | 0 |
EXAMPLE QUERY
SELECT
id AS send_id,
opens + clicks AS engagement_actions
FROM marketing.email_sends
ORDER BY send_id;RESULT — exact output from the displayed Queryflo rows
| send_id | engagement_actions |
|---|---|
| 201 | 720 |
| 202 | 516 |
| 203 | 835 |
| 204 | 0 |
Each value is the actual opens-plus-clicks sum for one email send.
Now You Try
Practice this concept
Marketing wants total engagement from opens and clicks for each email send.
Available schema
marketingPrefix tables with marketing.table_name.
send_idengagement_actionsmarketing.email_sends| Column | Type |
|---|---|
| id | integer |
| campaign_id | integer |
| sent_at | timestamp with time zone |
| recipients | integer |
| opens | integer |
| clicks | integer |
| unsubscribes | integer |
| bounces | integer |
| legacy_send_group | text |
query.sql
Sign up free to try it on a real business scenario