Beginner

292. ABS Function

Learn how to return the absolute value of a number.

📘 Lesson 292 of 728 ⏱ 9 min 🎯 Beginner

The ABS function returns the absolute value of a numeric expression, removing its negative sign while preserving its magnitude.

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

Calculate the absolute difference between actual sales and target sales.

SQL
SELECT
    EmployeeID,
    ABS(ActualSales - TargetSales) AS SalesVariance
FROM EmployeeSales;

ABS is useful in financial variance analysis, error calculations, distance calculations, and performance reporting.

  • 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 commonly used?

ABS is commonly used for calculating absolute differences, variances, and error amounts.

Have you finished this lesson?

Introduction to SQL – All Lessons