Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Abs Function In Sql in SQL

Abs Function In Sql in SQL

? ABS() Function in SQL

The ABS() function in SQL returns the absolute (positive) value of a number — it removes any negative sign.


? Syntax

SELECT ABS(number);

? Example Usage

1. Basic Example

SELECT ABS(-100) AS result;-- Output: 100

2. With a Table

Assume a table transactions:

idamount
1-500
2300
3-150

Query:

SELECT id, ABS(amount) AS abs_amountFROM transactions;

Result:

idabs_amount
1500
2300
3150

? Use Cases

  • Financial calculations (e.g., profit/loss)

  • Distance measurements (difference between values)

  • Normalization of values


? Supported In

  • ? MySQL

  • ? PostgreSQL

  • ? SQL Server

  • ? Oracle

  • ? SQLite


? Tip

ABS() works on both integer and decimal types.

SELECT ABS(-5.75); -- Output: 5.75

Let me know if you want practical problems or query examples using ABS() with joins or conditions!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql