SQL/MySQL/Function/SIGN

Материал из SQL эксперт
Перейти к: навигация, поиск

Use SIGN function

   <source lang="sql">

/* SIGN function returns the sign of the supplied value X as -1, 0, or 1, depending on whether the value X is negative, zero, or positive, respectively.

  • /

select SIGN(0); select SIGN(-3); select SIGN(3); /* mysql> select SIGN(0); +---------+ | SIGN(0) | +---------+ | 0 | +---------+ 1 row in set (0.00 sec) mysql> select SIGN(-3); +----------+ | SIGN(-3) | +----------+ | -1 | +----------+ 1 row in set (0.00 sec) mysql> select SIGN(3); +---------+ | SIGN(3) | +---------+ | 1 | +---------+ 1 row in set (0.00 sec)

  • /
      </source>