MySQL中的数学函数
2017-01-08 02:20
369 查看
1. bin
将十进制数值转换为二进制数值。MariaDB [test]> select bin(11); +---------+ | bin(11) | +---------+ | 1011 | +---------+
2. ceiling
进一法取整。MariaDB [test]> select ceiling(3.2); +--------------+ | ceiling(3.2) | +--------------+ | 4 | +--------------+
3. floor
舍去法取整。MariaDB [test]> select floor(3.2); +------------+ | floor(3.2) | +------------+ | 3 | +------------+
4. round
四舍五入取整。MariaDB [test]> select round(3.3), round(3.5); +------------+------------+ | round(3.3) | round(3.5) | +------------+------------+ | 3 | 4 | +------------+------------+
5. truncate
截取浮点数,第二个参数指定保留的小数位数。MariaDB [test]> select truncate(3.1415926, 2), truncate(3.1415926, 4); +------------------------+------------------------+ | truncate(3.1415926, 2) | truncate(3.1415926, 4) | +------------------------+------------------------+ | 3.14 | 3.1415 | +------------------------+------------------------+
6. format
对数值进行千分位格式化,第二个参数指定保留的小数位数(会进行四舍五入)。MariaDB [test]> select format(3150.46358, 2), format(3150.46358, 3); +-----------------------+-----------------------+ | format(3150.46358, 2) | format(3150.46358, 3) | +-----------------------+-----------------------+ | 3,150.46 | 3,150.464 | +-----------------------+-----------------------+ 1 row in set (0.00 sec)
7. max
取最大值。8. min
取最小值。9. sum
求和。10. sign
返回数值的符号。(负数返回-1,0返回0,正数返回1)MariaDB [test]> select sign(-3), sign(0), sign(3); +----------+---------+---------+ | sign(-3) | sign(0) | sign(3) | +----------+---------+---------+ | -1 | 0 | 1 | +----------+---------+---------+
11. power
幂运算。MariaDB [test]> select sign(-3), sign(0), sign(3); +----------+---------+---------+ | sign(-3) | sign(0) | sign(3) | +----------+---------+---------+ | -1 | 0 | 1 | +----------+---------+---------+
12. sqrt
求平方根。MariaDB [test]> select sqrt(9), sqrt(64); +---------+----------+ | sqrt(9) | sqrt(64) | +---------+----------+ | 3 | 8 | +---------+----------+
13. rand
返回0~1之间的随机数。MariaDB [test]> select rand(), rand(); +--------------------+--------------------+ | rand() | rand() | +--------------------+--------------------+ | 0.6072439082034341 | 0.7944739868812952 | +--------------------+--------------------+
相关文章推荐
- 整理了下MySQL内置函数表,包括字符串函数、数学函数和日期时间函数
- Mysql数学函数不求人
- MySQL内建函数表(包括字符串函数、数学函数和日期时间函数)
- mysql中的数学函数
- 整理了下MySQL内置函数表,包括字符串函数、数学函数和日期时间函数
- MySQL 内置数学函数
- MySQL笔记之数学函数详解
- MySQL学习笔记18:数学函数
- MySQL学习笔记18:数学函数
- Mysql数学函数不求人
- Mysql数学函数不求人
- mysql 中数学函数的使用
- MySQL笔记之数学函数详解
- mysql的数学函数
- Mysql数学函数不求人
- Mysql数学函数解析
- MySQL内置函数表(包括字符串函数、数学函数和日期时间函数)
- mysql常用的数学函数
- MySQL好用的数学函数