ABS
- SQL course
- Beginner
- Lesson 49/115
- 4 min
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
-- absolute value
SELECT
FROM accountsSample solution
SELECT ABS(balance) AS mutlak
FROM accountsExpected 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
SELECT ____(balance) FROM accounts;
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.