Beginner

210. ABS Function

Learn how to return the absolute value of a number.

📘 Lesson 210 of 728 ⏱ 8 min 🎯 Beginner

The ABS function returns the absolute value of a numeric expression, converting a negative value to its positive magnitude while leaving positive values unchanged.

Absolute values are useful when the direction of a difference does not matter and only the size of the difference is important.

Calculate the absolute difference between expected and actual sales.

SQL
SELECT
    EmployeeName,
    ABS(TargetSales - ActualSales) AS SalesVariance
FROM SalesPerformance;

ABS is useful for variance analysis, error measurement, financial comparisons, performance analysis, and reconciliation.

  • ABS returns a non-negative value.
  • Negative values become positive.
  • Positive values remain unchanged.
  • Zero remains zero.
  • It is useful for variance analysis.
What does ABS do?

ABS returns the absolute value of a numeric expression.

Where is ABS useful?

ABS is useful when measuring the magnitude of differences without considering whether the difference is positive or negative.

Have you finished this lesson?

Introduction to SQL – All Lessons