SQL ABS
Returns the absolute value — strips away a negative sign, leaving positive numbers untouched.
What & Why
ABS(n) returns the non-negative version of a number — a positive number is returned unchanged, a negative one has its sign flipped. Useful whenever only the size of a difference matters, not its direction.
See How It Works
BUSINESS QUESTION
Growth wants the absolute gap between DAU and new users for each day.
| date_day | dau | new_users | returning_users |
|---|---|---|---|
| 2024-04-01 | 1240 | 180 | 1060 |
| 2024-04-02 | 1315 | 205 | 1110 |
| 2024-04-03 | 1288 | 164 | 1124 |
| 2024-04-04 | 1392 | 221 | 1171 |
EXAMPLE QUERY
SELECT
date_day,
dau,
new_users,
ABS(dau - new_users) AS absolute_gap
FROM growth.daily_active_users
ORDER BY date_day;RESULT — exact output from the displayed Queryflo rows
| date_day | dau | new_users | absolute_gap |
|---|---|---|---|
| 2024-04-01 | 1240 | 180 | 1060 |
| 2024-04-02 | 1315 | 205 | 1110 |
| 2024-04-03 | 1288 | 164 | 1124 |
| 2024-04-04 | 1392 | 221 | 1171 |
ABS returns the real magnitude between DAU and new users for each date.
Now You Try
Practice this concept
Growth wants the absolute gap between DAU and new users for every day.
Available schema
growthPrefix tables with growth.table_name.
date_daydaunew_usersabsolute_gapgrowth.daily_active_users| Column | Type |
|---|---|
| date_day | date |
| dau | integer |
| new_users | integer |
| returning_users | integer |
| internal_tracking_code | text |
growth.users| Column | Type |
|---|---|
| id | integer |
| created_at | timestamp with time zone |
| country | text |
| channel | text |
| plan | text |
| activated_at | timestamp with time zone |
| churned_at | timestamp with time zone |
| legacy_user_code | text |
query.sql
Sign up free to try it on a real business scenario