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_daydaunew_usersreturning_users
2024-04-0112401801060
2024-04-0213152051110
2024-04-0312881641124
2024-04-0413922211171
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_daydaunew_usersabsolute_gap
2024-04-0112401801060
2024-04-0213152051110
2024-04-0312881641124
2024-04-0413922211171

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
growth

Prefix tables with growth.table_name.

date_daydaunew_usersabsolute_gap
growth.daily_active_users
ColumnType
date_daydate
dauinteger
new_usersinteger
returning_usersinteger
internal_tracking_codetext
growth.users
ColumnType
idinteger
created_attimestamp with time zone
countrytext
channeltext
plantext
activated_attimestamp with time zone
churned_attimestamp with time zone
legacy_user_codetext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario