dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Nov 8, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Knowing the Sign of a Given Number in MySQL

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  |
+-------+ 
M S Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date