Hey guys, I'm currently testing my application with some scripts I have written. I'm using the following query to list known errors within my application, and the status of the tests that are are affected by each error:
SELECT
ERROR.BG_ERROR_ID,
ERROR.BG_USER_03 as HardwareID,
count (RUN.CY_RUN_ID) as NumAffected,
sum (CASE RUN.RESULT when 'Passed' THEN 1 else 0 end) as Passed,
sum (CASE RUN.RESULT when 'Failed' THEN 1 else 0 end) as Failed,
FROM ERROR
INNER JOIN LINK on ERROR.BG_ERROR_ID = LINK.LN_ERROR_ID
INNER JOIN TESTCYCL on TESTCYCL.TC_TESTCYCL_ID = LINK.LN_ENTITY_ID
INNER JOIN RUN on TESTCYCL.TC_RUN_ID = RUN.CY_RUN_ID
WHERE ERROR.BG_STATUS != 'Closed'
AND LINK.LN_ENTITY_TYPE = 'TESTCYCL'
group by ERROR.BG_ERROR_ID, ERROR.BG_USER_03
order by NumAffected DESC
A run of this query produces something like:
BG_ERROR_ID.....HardwareID.....NumAffected.....Passed.....Failed
----------------------------------------------------------------
286.............87526..........10..............5..........5
226.............82309..........20..............15.........5
233.............17526..........21..............5..........16
586.............23346..........3...............2..........1
555.............87886..........10..............9..........1
200.............27526..........12..............5..........7
As you can see, the number of Passed and Failed combined amounts to the NumAffected. However, what I really need to be doing is a distinct count on NumAffected, i.e.:
SELECT
ERROR.BG_ERROR_ID,
ERROR.BG_USER_03 as HardwareID,
count (distinct RUN.CY_RUN_ID) as NumAffected,
sum (CASE RUN.RESULT when 'Passed' THEN 1 else 0 end) as Passed,
sum (CASE RUN.RESULT when 'Failed' THEN 1 else 0 end) as Failed,
FROM ERROR
INNER JOIN LINK on ERROR.BG_ERROR_ID = LINK.LN_ERROR_ID
INNER JOIN TESTCYCL on TESTCYCL.TC_TESTCYCL_ID = LINK.LN_ENTITY_ID
INNER JOIN RUN on TESTCYCL.TC_RUN_ID = RUN.CY_RUN_ID
WHERE ERROR.BG_STATUS != 'Closed'
AND LINK.LN_ENTITY_TYPE = 'TESTCYCL'
group by ERROR.BG_ERROR_ID, ERROR.BG_USER_03
order by NumAffected DESC
A run of this query produces something like:
BG_ERROR_ID.....HardwareID.....NumAffected.....Passed.....Failed
----------------------------------------------------------------
286.............87526..........7...............5..........5
226.............82309..........13..............15.........5
233.............17526..........10..............5..........16
586.............23346..........2...............2..........1
555.............87886..........4...............9..........1
200.............27526..........10..............5..........7
As you can see, the number of NumAffected has now dropped, and Passed and Failed no longer amount to NumAffected. What can I change in my query to make Passed and Failed amount to distinct NumAffected?
If I try to do a distinct sum on Passed and Failed, e.g.:
SELECT
ERROR.BG_ERROR_ID,
ERROR.BG_USER_03 as HardwareID,
count (distinct RUN.CY_RUN_ID) as NumAffected,
sum (distinct CASE RUN.RESULT when 'Passed' THEN 1 else 0 end) as Passed,
sum (distinct CASE RUN.RESULT when 'Failed' THEN 1 else 0 end) as Failed,
FROM ERROR
INNER JOIN LINK on ERROR.BG_ERROR_ID = LINK.LN_ERROR_ID
INNER JOIN TESTCYCL on TESTCYCL.TC_TESTCYCL_ID = LINK.LN_ENTITY_ID
INNER JOIN RUN on TESTCYCL.TC_RUN_ID = RUN.CY_RUN_ID
WHERE ERROR.BG_STATUS != 'Closed'
AND LINK.LN_ENTITY_TYPE = 'TESTCYCL'
group by ERROR.BG_ERROR_ID, ERROR.BG_USER_03
order by NumAffected DESC
I get something like:
BG_ERROR_ID.....HardwareID.....NumAffected.....Passed.....Failed
----------------------------------------------------------------
286.............87526..........7...............1..........1
226.............82309..........13..............1..........1
233.............17526..........10..............1..........1
586.............23346..........2...............1..........1
555.............87886..........4...............1..........1
200.............27526..........10..............1..........1
Please help, it's very much appreciated!
Thanks