AnalyticDB for MySQL supports the following arithmetic operators.

+ Addition.
- Subtraction.
* Multiplication.
/ Division.
DIV Integer division.
% or MOD Modulo.
- Changes the sign of the argument.

+

  • Description: This operator is used for addition.
  • Example:
    select 3+5;
    +-------+
    | _col0 |
    +-------+
    |     8 | 
    select 3+2.9875;
    +--------+
    | _col0  |
    +--------+
    | 5.9875 |

-

  • Description: This operator is used for subtraction.
  • Example:
    select 3-5;
    +-------+
    | _col0 |
    +-------+
    |    -2 |
    select 3-1.5;
    +-----------+
    | _col0     |
    +-----------+
    | 1.5       |

*

  • Description: This operator is used for multiplication.
  • Example:
    select 3*pi();
    +------------------+
    | _col0            |
    +------------------+
    | 9.42477796076938 |

/

  • Description: This operator is used for division.
  • Example:
    select 3/pi();
    +-------------------+
    | _col0             |
    +-------------------+
    | 0.954929658551372 |

DIV

  • Description: This operator is used for division. The decimal part of the result is discarded.
  • Example:
    select 3 div pi();
    +-------+
    | _col0 |
    +-------+
    |     0 |
    select 33 div 2;
    +-------+
    | _col0 |
    +-------+
    |    16 |

% or MOD

  • Description: This operator returns the remainder of one argument divided by the other argument.
  • Example:
    select 3 mod pi();
    +-------+
    | _col0 |
    +-------+
    |   3.0 |
    select 33 % 2;
    +-------+
    | _col0 |
    +-------+
    |     1 |

-

  • Description: This operator converts a positive number to a negative number or a negative number to a positive number.
  • Example:
    select - 2;
    +-------+
    | _col0 |
    +-------+
    |    -2 |
    select - 2;
    +-------+
    | _col0 |
    +-------+
    |    -2 |