MariaDB - Divide (/) Operator
The MariaDB / (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:
Data | Var1 | Var2 |
---|---|---|
Data1 | 10.0 | 1.0 |
Data2 | 15.0 | 2.0 |
Data3 | 20.0 | 3.0 |
Data4 | 25.0 | 4.0 |
Data5 | 30.0 | 5.0 |
Data6 | 35.0 | 6.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:
Data Var1 Var2 Data1 10.0 1.0 Data2 15.0 2.0 Data3 20.0 3.0 Data4 25.0 4.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:
Data Var1 Var2 Division Data1 10.0 1.0 10.0 Data2 15.0 2.0 7.5 Data3 20.0 3.0 6.66666666666667 Data4 25.0 4.0 6.25 Data5 30.0 5.0 6.0 Data6 35.0 6.0 5.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:
Data Var1 Var2 Data1 10.0 1.0 Data2 7.5 2.0 Data3 6.66666666666667 3.0 Data4 6.25 4.0 Data5 6.0 5.0 Data6 5.83333333333333 6.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
❮ MariaDB Operators