[英]Combine two queries in Oracle
I have 2 queries to retrieve faultCount
and responseCount
as follows and it works fine. 我有2个查询来检索faultCount
和responseCount
,如下所示,它工作正常。
select count(*) as faultCount,
COMP_IDENTIFIER
from CORDYS_NCB_LOG
where AUDIT_CONTEXT='FAULT'
group by COMP_IDENTIFIER
order by responseCount;
select count(*) as responseCount,
COMP_IDENTIFIER
from CORDYS_NCB_LOG
where AUDIT_CONTEXT='RESPONSE'
group by COMP_IDENTIFIER
order by responseCount;
I need to join to get the columns like this: COMP_IDENTIFIER,faultCount,responseCount
. 我需要加入以获得这样的列: COMP_IDENTIFIER,faultCount,responseCount
。 The following query does the job. 以下查询可以完成这项工作。 But it takes a long time to execute (> 16 sec). 但是执行时间很长(> 16秒)。
select count(case AUDIT_CONTEXT when 'FAULT' then 1 end) as faultCount,
count(case AUDIT_CONTEXT when 'RESPONSE' then 1 end) as responseCount,
COMP_IDENTIFIER
from CORDYS_NCB_LOG
group by COMP_IDENTIFIER
order by responseCount;
I'm looking for a simple and faster query. 我正在寻找一个简单,快速的查询。 Thanks in advance. 提前致谢。
One possible reason this is taking longer is that you're reading all rows in CORDYS_NCB_LOG
even where AUDIT_CONTEXT
is not FAULT
or RESPONSE
, which are the only rows you're interested in. 这可能需要更长的时间,原因之一是您正在读取CORDYS_NCB_LOG
所有行,即使AUDIT_CONTEXT
不是FAULT
或RESPONSE
,这也是您唯一感兴趣的行。
You can add this to the WHERE
clause of your existing query: 您可以将其添加到现有查询的WHERE
子句中:
select count(case AUDIT_CONTEXT when 'FAULT' then 1 end) as faultCount,
count(case AUDIT_CONTEXT when 'RESPONSE' then 1 end) as responseCount,
COMP_IDENTIFIER
from CORDYS_NCB_LOG
where AUDIT_CONTEXT in ('FAULT', 'RESPONSE')
group by COMP_IDENTIFIER
order by responseCount;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.