CodeBlanks Logo Icon CodeBlanks

ABS

Take the absolute value of a number.

ABS

ABS returns the absolute value of a number; it makes negatives positive.

SELECT ABS(balance) AS mutlak FROM accounts;

This query returns the positive form of a negative balance.

ABS(balance) AS mutlak is selected from accounts.

ABS — details

ABS(-5) = 5, ABS(5) = 5. It is used to show debt values as positive in balance calculations.

Practice ABS

Select the absolute value of balance aliased as mutlak from accounts.

Starter code

query.sql
-- absolute value
SELECT
FROM accounts

Sample solution

query.sql
SELECT ABS(balance) AS mutlak
FROM accounts

Expected output

mutlak
50
30

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 ABS: match the terms

Term Meaning
ABS absolute
ROUND round
CEIL up
FLOOR down

2 Absolute value

Question
SELECT ____(balance) FROM accounts;
Answer
SELECT ABS(balance) FROM accounts;

Explanation: ABS returns the absolute value; a negative balance becomes positive.

3 What is ABS(-7)?

  • 14
  • 0
  • -7
  • 7 Correct answer

Explanation: ABS makes a negative positive.

All lessons in Beginner