I have 2 queries to retrieve faultCount
and responseCount
as follows and it works fine.
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
. The following query does the job. But it takes a long time to execute (> 16 sec).
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 whereAUDIT_CONTEXT
is notFAULT
orRESPONSE
, which are the only rows you're interested in.You can add this to the
WHERE
clause of your existing query: