MySQL Tutorial MySQL Advanced MySQL Database Account Management MySQL References

MySQL - Divide (/) Operator



The MySQL / (divide) operator is used to divide two values. It operates on numerical values.

The example below describes how to use divide operator in various conditions:

Example:

Consider a database table called Sample with the following records:

DataVar1Var2
Data110.01.0
Data215.02.0
Data320.03.0
Data425.04.0
Data530.05.0
Data635.06.0

  • Using with WHERE Clause: To select records of table where division of Var1 column value by Var2 column value is greater than 6.0, the query is given below.

    SELECT * FROM Sample
    WHERE Var1 / Var2 > 6.0;
    

    The query will produce following result:

    DataVar1Var2
    Data110.01.0
    Data215.02.0
    Data320.03.0
    Data425.04.0
  • Using with AS Clause: The division of Var1 column value by Var2 column value can be displayed in a different column using AS clause:

    SELECT *, (Var1 / Var2) AS Division FROM Sample;
    

    The query will produce following result:

    DataVar1Var2Division
    Data110.01.010.0
    Data215.02.07.5
    Data320.03.06.66666666666667
    Data425.04.06.25
    Data530.05.06.0
    Data635.06.05.83333333333333
  • Using with UPDATE Clause: To update the column Var1 with the division of Var1 column value by Var2 column value, the query is given below:

    UPDATE Sample
    SET Var1 = Var1 / Var2;
    
    --See result
    SELECT * FROM Sample;
    

    The query will produce following result:

    DataVar1Var2
    Data110.01.0
    Data27.52.0
    Data36.666666666666673.0
    Data46.254.0
    Data56.05.0
    Data65.833333333333336.0
  • Using with values: To divide two values, we can simply use SELECT statement:

    SELECT 50 / 25;
    

    The query will produce following result:

    50 / 25
    2

❮ MySQL Operators