mysql数据库教程函数之数字类
mysql数据库教程函数之数字类语法代码:
-- 获取随机数
mysql> select rand();
+------------------+
| rand() |
+------------------+
| 0.25443412666622 |
+------------------+
1 row in set (0.00 sec)
-- 随机排序
mysql> select * from stuinfo order by rand();
-- 随机获取一条记录
mysql> select * from stuinfo order by rand() limit 1;
-- 四舍五入,向上取整,向下取整
mysql> select round(3.1415926,3) '四舍五入',truncate(3.14159,3) '截取数据',ceil(3.1) '向上取整',floor(3.9) '向下取整';
+----------+----------+----------+----------+
| 四舍五入| 截取数据| 向上取整 | 向下取整 |
+----------+----------+----------+----------+
| 3.142 | 3.141 | 4 | 3 |
+----------+----------+----------+----------+
1 row in set (0.04 sec)
注意: 截取数据直接截取,不四舍五入
页:
[1]