Oracle sql - 比计算量更好

时间:2017-09-20 11:58:31

标签: sql oracle

我收到了这个脚本来执行:

SELECT b.tablespace_name,
       tbs_size SizeMb,
       a.free_space FreeMb,
       CAST(round(((tbs_size - a.free_space)/tbs_size)*100,2)AS VARCHAR(6)) || '%'
         PercentFull
FROM   (
         SELECT tablespace_name,
                round(SUM(bytes)/1024/1024 ,2) AS free_space
          FROM   dba_free_space
          GROUP BY tablespace_name
        ) a,
        (
          SELECT tablespace_name,
                 SUM(bytes)/1024/1024 AS tbs_size
          FROM   dba_data_files
          GROUP BY tablespace_name
          UNION
          SELECT tablespace_name,
                 SUM(bytes)/1024/1024 tbs_size
          FROM   dba_temp_files
          GROUP BY tablespace_name
        ) b
WHERE a.tablespace_name(+)=b.tablespace_name;

scores without zero before

第一个问题是' 0'在得分之间,我改为:

SELECT b.tablespace_name,
       tbs_size SizeMb,
       a.free_space FreeMb,
       TO_CHAR(round(((tbs_size - a.free_space)/tbs_size)*100,2),'00.99' ) || '%'
         PercentFull
FROM   (
         SELECT tablespace_name,
                round(SUM(bytes)/1024/1024 ,2) AS free_space
         FROM dba_free_space
         GROUP BY tablespace_name
       ) a,
       (
         SELECT tablespace_name,
                SUM(bytes)/1024/1024 AS tbs_size
         FROM   dba_data_files
         GROUP BY tablespace_name
         UNION
         SELECT tablespace_name,
                SUM(bytes)/1024/1024 tbs_size
         FROM   dba_temp_files
         GROUP BY tablespace_name
       ) b
WHERE a.tablespace_name(+)=b.tablespace_name;

scores with lost zero

现在我已经失去了零,但我仍然找不到解决方案,如何显示分数大于50%。 - 你能帮助我吗?

2 个答案:

答案 0 :(得分:0)

如果您只想接收百分比大于50%的行,您可以将此限制添加到use App\Event\CommentListener; use Cake\Event\EventManager; $CommentListener = new CommentListener(); EventManager::instance()->on($CommentListener); // REPLACED 'attach' here with 'on' - 子句,如:

WHERE

答案 1 :(得分:0)

解决方案:

SELECT b.tablespace_name, 
       tbs_size SizeMb, 
       a.free_space FreeMb, 
       TO_CHAR(round(((tbs_size - a.free_space)/tbs_size)*100,2),'00.99' ) || '%' 
       PercentFull 
FROM (
       SELECT tablespace_name, 
              round(SUM(bytes)/1024/1024 ,2) AS free_space 
              FROM dba_free_space 
              GROUP BY tablespace_name
      ) a, 
      (
       SELECT tablespace_name, 
              SUM(bytes)/1024/1024 AS tbs_size 
              FROM dba_data_files 
              GROUP BY tablespace_name 
              UNION 
              SELECT tablespace_name, 
                     SUM(bytes)/1024/1024 tbs_size 
              FROM dba_temp_files 
              GROUP BY tablespace_name 
      ) b 
WHERE a.tablespace_name(+)=b.tablespace_name 
      and (((tbs_size - a.free_space)/tbs_size)*100)>50;