mysql命令

1.时间取整,取整10分

 

mysql> SELECT  date_add(now(),interval -(TIME_TO_SEC(now()) mod 600) second);
+---------------------------------------------------------------+
| date_add(now(),interval -(TIME_TO_SEC(now()) mod 600) second) |
+---------------------------------------------------------------+
| 2012-07-14 17:20:00                                           |
+---------------------------------------------------------------+
1 row in set

(orcle为select sysdate - mod(((sysdate-TO_DATE('19700101','yyyymmdd'))*3600*24),900)/(3600*24) from dual

2.数字向上取整:

 

mysql> select ceil(1.51245
);
+---------------+
| ceil(1.51245) |
+---------------+
|             2 |
+---------------+
1 row in set

 3.数字向下取整

 

mysql> select floor
(1.51245);
+----------------+
| floor(1.51245) |
+----------------+
|              1 |
+----------------+
1 row in set
 

4.四舍五入

 

mysql> select round(1.51245);
+----------------+
| round(1.51245) |
+----------------+
| 2              |
+----------------+
1 row in set

 5.保留设定小数位四舍五入

 

mysql> select round(1.51245,2
);
+------------------+
| round(1.51245,2) |
+------------------+
| 1.51             |
+------------------+
1 row in set
  

 

 

 

你可能感兴趣的:(mysql)