比如有这么一个查询:

mysql> select s.schema_name as "DB Name",ifnull(concat(round(sum(t.data_length/1024/1024),4),'MB'),'No Tables Created') as "Size" from information_schema.SCHEMATA s left join information_schema.tables t on s.SCHEMA_NAME=t.TABLE_SCHEMA group by s.schema_name
    -> ;
+--------------------+----------+
| DB Name            | Size     |
+--------------------+----------+
| mysql              | 2.1250MB |
| information_schema | 0.0000MB |
| performance_schema | 0.0000MB |
| sys                | 0.0156MB |
| adamhuan           | 0.0469MB |
+--------------------+----------+
5 rows in set (0.40 sec)

mysql> 

可以看到,结果中有很多小数位;

我们希望对小数位,向上取整;
可以这么做:

mysql> select s.schema_name as "DB Name",ifnull(ceiling(sum(t.data_length/1024/1024)),'No Tables Created') as "Size" from information_schema.SCHEMATA s left join information_schema.tables t on s.SCHEMA_NAME=t.TABLE_SCHEMA group by s.schema_name;       
+--------------------+------+
| DB Name            | Size |
+--------------------+------+
| mysql              | 3    |
| information_schema | 0    |
| performance_schema | 0    |
| sys                | 1    |
| adamhuan           | 1    |
+--------------------+------+
5 rows in set (0.01 sec)

mysql> 

如上,使用了函数【ceiling()】。


说点什么

avatar

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

  Subscribe  
提醒