gpt4 book ai didi

sql - 如何使用 SQL 减去值

转载 作者:行者123 更新时间:2023-12-02 08:34:47 24 4
gpt4 key购买 nike

你能告诉我如何减去值吗?

SQL>

select SUM(bytes/1024/1024) from dba_data_files where TABLESPACE_NAME='UNDOTBS1'

2 ;

SUM(BYTES/1024/1024)
--------------------
7000

SQL>

select SUM(BYTES/1024/1024) from DBA_UNDO_EXTENTS where STATUS LIKE 'ACTIVE';

SUM(BYTES/1024/1024)
--------------------
8

我需要得到一个值 7000 - 8

当我这样做

select SUM(bytes/1024/1024) from dba_data_files where TABLESPACE_NAME='UNDOTBS1'
minus
select SUM(BYTES/1024/1024) from DBA_UNDO_EXTENTS where STATUS='ACTIVE';

我只从第一个选择中得到结果。

最佳答案

在这里使用对偶伪表并将总和计算为标量:

SELECT 
(SELECT SUM(bytes/1024/1024) as sum_a
from dba_data_files where TABLESPACE_NAME='UNDOTBS1')
- (select SUM(BYTES/1024/1024) as sum_b
from DBA_UNDO_EXTENTS where STATUS LIKE 'ACTIVE') as Difference
FROM
dual;

关于sql - 如何使用 SQL 减去值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22943977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com