MySQL Arithmetic Operators
MySQL 산술연산자 쯤?
Arithmetic Operators
Name | Description |
%, MOD | Modulo operator |
* | Multiplication operator |
+ | Addition Operator |
- | Minus Operator |
- | Change the sign of the argument |
/ | Division operator |
DIV | Integer division |
평소에 많이 봐왔던 것들이다.
DIV
Integer division. Discards from the division result any fractional part to the right of the decimal point.
If either operand has a noninteger type, the operands are converted to DECIMAL and divided using DECIMAL arithmetic before converting the result to BIGINT. If the result exceeds BIGINT range, an error occurs.
mysql> SELECT 5 DIV 2, -5 DIV 2, 5 DIV -2, -5 DIV -2 ;
+---------+----------+----------+-----------+
| 5 DIV 2 | -5 DIV 2 | 5 DIV -2 | -5 DIV -2 |
+---------+----------+----------+-----------+
| 2 | -2 | -2 | 2 |
+---------+----------+----------+-----------+
1 row in set (0.00 sec)
mysql> SELECT 5 / 2 ;
+--------+
| 5 / 2 |
+--------+
| 2.5000 |
+--------+
1 row in set (0.00 sec)