[英]Combine two queries in Oracle
我有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;
我需要加入以獲得這樣的列: COMP_IDENTIFIER,faultCount,responseCount
。 以下查詢可以完成這項工作。 但是執行時間很長(> 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;
我正在尋找一個簡單,快速的查詢。 提前致謝。
這可能需要更長的時間,原因之一是您正在讀取CORDYS_NCB_LOG
所有行,即使AUDIT_CONTEXT
不是FAULT
或RESPONSE
,這也是您唯一感興趣的行。
您可以將其添加到現有查詢的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.