Feb 18
Numeric operators are used in a similar waytwo values appear on either side of a symbol or a sequence of symbols. This expression equates to a new value in the SQL statement.
Operators and Operands
In the expression a + b, the + symbol is the operator and a and b are known as operands.
Using Arithmetic Operators
An expression that uses a numeric operator can be used in a SQL statement anywhere that you could otherwise put a numeric value. You can also use a numeric operator to modify retrieved data from a table, as long as it is numeric data.
You can actually perform a query in MySQL without supplying a table name. This is useful only when you have an expression as a selected value, but it can be used to show the result of an expression on fixed values.
Addition in MySQL is performed using the + operator, and subtraction using the - operator. The following query shows an expression using each of these operators:
mysql> SELECT 15 + 28, 94 - 55;
+——– +———+
| 15 + 28 | 94 - 55 |
+———+———+
| 43 | 39 |
+———+———+
1 row in set (0.00 sec)
A query with no table list returns exactly one row but can contain multiple columns. In this example, the two columns returned contain the results of the two expressions in the
SELECT statement.
The other basic arithmetic operators in MySQL are * and /, for multiplication and division, respectively. The / operator in MySQL returns a decimal numberit does not truncate the result or round it to the nearest whole number.
mysql> SELECT 6 * 8, 72 / 9, 2 / 3;
+——-+——–+——-+
| 6 * 8 | 72 / 9 | 2 / 3 |
+——-+——–+——-+
| 48 | 8.00 | 0.67 |
+——-+——–+——-+
1 row in set (0.00 sec)
Popularity: 7% [?]
last comments