• Learning MySQL By Example
  • Introduction
  • 1. How to Retrieve Data From a Single Table
  • 2. How to Retrieve Data from Multiple Tables
  • 3. Using Functions
  • 4. How to Insert, Update, Delete Data in Tables
  • 5. Summary Queries and Aggregate Functions
  • 6. Working With Subqueries
  • 7. SQL Views
  • 8. SQL Indexes
  • Glossary
  • Index
  • Download
  • Translations
  • 1.4

    Arithmetic Operators

    Arithmetic Operators

    • Arithmetic operators can be used in the SELECT, WHERE, and ORDER BY clauses.
    • Operators are evaluated in the same way as arithmetic in other contexts.


    Table 4. Operators and precedence order

    Operator Name Order of Precedence

    *

    Multiplication

    1

    /

    Division

    1

    DIV

    Integer Division

    1

    % (MOD)

    Modulo (remainder)

    1

    +

    Addition

    2

    -

    Subtraction

    2

    Code Example:

    USE world;
    SELECT name, population / SurfaceArea
    AS "People per square mile"
    FROM country;

    Results:

    arithmetic.png

    This content is provided to you freely by EdTech Books.

    Access it online or download it at https://edtechbooks.org/learning_mysql/14_arithmetic_operat.