All Products
Search
Document Center

:Arithmetic operators

Last Updated:Sep 11, 2024

You can use arithmetic operators together with constants or fields to perform mathematical calculations. This topic describes the arithmetic operators that are supported by AnalyticDB for MySQL.

+

Performs the addition operation.

-

Performs the subtraction operation.

*

Performs the multiplication operation.

/

Performs the division operation.

DIV

Performs the division operation and returns a truncated integer result.

% or MOD

Returns the remainder of one argument divided by the other argument.

-

Changes the sign of the argument.

+

  • Description: This operator performs the addition operation.

  • Examples:

    select 3+5;
    +-------+
    | _col0 |
    +-------+
    |     8 | 
    select 3+2.9875;
    +--------+
    | _col0  |
    +--------+
    | 5.9875 |

-

  • Description: This operator performs the subtraction operation.

  • Examples:

    select 3-5;
    +-------+
    | _col0 |
    +-------+
    |    -2 |
    select 3-1.5;
    +-----------+
    | _col0     |
    +-----------+
    | 1.5       |

*

  • Description: This operator performs the multiplication operation.

  • Example:

    select 3*pi();
    +------------------+
    | _col0            |
    +------------------+
    | 9.42477796076938 |

/

  • Description: This operator performs the division operation.

  • Example:

    select 3/pi();
    +-------------------+
    | _col0             |
    +-------------------+
    | 0.954929658551372 |

DIV

  • Description: This operator performs the division operation and returns a truncated integer result.

  • Examples:

    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.

  • Examples:

    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.

  • Examples:

    select - 2;
    +-------+
    | _col0 |
    +-------+
    |    -2 |
    select - -2;
    +-------+
    | _col0 |
    +-------+
    |     2 |