웹이야기

MySQL Arithmetic Operators 본문

D/MySQL

MySQL Arithmetic Operators

yeon.Biju 2020. 3. 26. 16:00

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)

'D > MySQL' 카테고리의 다른 글

MySQL ABS()  (0) 2020.03.26
MySQL Mathematical Functions  (0) 2020.03.26
MySQL Control Flow Functions  (0) 2020.03.19
MySQL 지정 연산자  (0) 2020.03.19
MySQL 논리 연산자  (0) 2020.03.18
Comments