TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
 Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow

# Tip: Knowing the Sign of a Given Number in MySQL

## See how to learn the sign of the number for computation purposes.

 by Sridhar M S
 Nov 8, 2018

For a given number, it may be necessary to know the sign of the number for computation purposes.

If it is positive, zero or negative, you may have respective case to work on. The signs are returned as 1, 0, -1 for positive number, zero and negative number respectively.

Case 1: Positive number

``````SELECT SIGN(234) AS SIGN;
where 234 is the value.

+-------+
| SIGN  |
+-------+
|    1  |
+-------+``````

Case 2: Number is zero

``````SELECT SIGN(0) AS SIGN;
where 0 is the value.

+-------+
| SIGN  |
+-------+
|    0  |
+-------+``````

Case 3: Negative number

``````SELECT SIGN(-64500) AS SIGN;
where -64500 is the value.

+-------+
| SIGN  |
+-------+
|   -1  |
+-------+ ``````

Visit the DevX Tip Bank

Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Email Author