Hi Guys,
I am trying to get a count of the number of failed SR's in the following query. The table I need to get the information from I cannot put into the main body of the query as it would bring some results back that I do not want. The query I have is as follows:
SELECT DISTINCT env_subtype_code,
std_count,
cust_count,
esc_sr,
fail_sr,
SUM(std_count+cust_count) total,
(esc_sr *100)/DECODE(SUM(std_count+cust_count),0,1,SUM(std_count+cust_count)) esc_per,
(fail_sr *100)/DECODE(SUM(std_count+cust_count),0,1,SUM(std_count+cust_count)) sentback_per
FROM
( SELECT DISTINCT env_subtype_code,
COUNT(
CASE
WHEN sr_type IN ('100', '231')
THEN 1
END) std_count,
COUNT(
CASE
WHEN sr_type = '101'
THEN 1
END ) cust_count,
COUNT(
CASE
WHEN escalated = 'Y'
AND upper(patch_status) = 'CLOSED'
AND group_name = 'AITSYS ESCALATIONS'
THEN 1
END ) esc_sr,
COUNT(
SELECT sent_back_date
FROM cprt_sent_back_srs
WHERE b.creation_date BETWEEN to_date('01-DEC-08', 'DD-MON-RR' ) AND to_date('31-DEC-08', 'DD-MON-RR')
) fail_sr
FROM cprt_request a,
cprt_patch_update b,
cprt_patch_sr c,
environment_subtype sub,
environment env,
GSA.GSA_SR_JTF_RS_GROUPS_VL gs
WHERE a.cprt_request_id = b.cprt_Request_id
AND b.cprt_patch_sr_id = c.cprt_patch_sr_id
AND b.patch_group = gs.group_id
AND a.sid = env.name
AND sub.id = env.env_subtype_id
AND to_date(b.sr_closed_date,'DD-MON-RR') BETWEEN to_date('01-DEC-08', 'DD-MON-RR' ) AND to_date('31-DEC-08', 'DD-MON-RR' )
AND env.type IN( 'Production','Test')
AND env.status <> 'Decommissioned'
AND (sub.env_subtype_code = '-1'
OR :P208_ENV = '-1')
GROUP BY env_subtype_code
ORDER BY env_subtype_code
)
GROUP BY env_subtype_code,
std_count,
cust_count,
esc_sr,
fail_sr
ORDER BY env_subtype_code
The part of the code I need to work but am getting errors with is:
COUNT(
SELECT sent_back_date
FROM cprt_sent_back_srs
WHERE b.creation_date BETWEEN to_date('01-DEC-08', 'DD-MON-RR' ) AND to_date('31-DEC-08', 'DD-MON-RR')
) fail_sr
The error I get is ORA-00936 - Missing Expression. I know this is probably because you cannot put a subquery into a count like I have. Is there anyway I can use the query in the count to show as a column in my query without putting the clause into the main body of my query?
Thanks
-Mark