I have a table with a Process name and when the process failed plus details. Another table with a Process name and when it was successful plus details.
I am trying to join them so I get the Process, some details, and the total times it failed and completed since July.
The result is multiplying the two COUNT columns together
SELECT e.Process, e.ExceptionType, e.ExceptionReason, COUNT(e.ExceptionType) AS 'Total Exceptions', COUNT(c.Process) AS 'Total Completions'
FROM Errors e
JOIN Completions c
ON c.Process = e.Process
AND '' NOT IN (e.ExceptionType, e.ExceptionReason, e.Process)
AND e.StartedTime > CONVERT(DATETIME, '2019-07-01', 102)
WHERE c.StartedTime > CONVERT(DATETIME, '2019-07-01', 102)
GROUP BY e.Process, e.ExceptionType, e.ExceptionReason
ORDER BY 'Total Exceptions' DESC
It returns what I would expect: The name of the process, the Type of failure, the Reason for failure but then the last two COUNT columns are multiplied together.
If I query these separately for example the first row has 'Total Exceptions' of 844 and 'Total Completions' of 1550
I have tried all JOINs and also tried COUNT(DISTINCT(...)) but then the last two columns return 1 for all rows.
Help?
MORE CONTEXT
select Process, ExceptionType, ExceptionReason, count(ExceptionType)
from Error
where StartedTime > CONVERT(DATETIME, '2019-07-01', 102) and '' NOT IN (Process, ExceptionType, ExceptionReason) and ExceptionType NOT LIKE 'Business%'
group by ExceptionType, Process, ExceptionReason
order by count(ExceptionType) DESC
Returns a row of:
Process_Name | Exception_Type | Exception_Reason | 844
And then the query:
select Process, count(Process)
from Complete
where CompletedTime > CONVERT(DATETIME, '2019-07-01', 102)
group by Process
order by count(Process) DESC, Process
Returns a row of:
Process_Name | 1550
What I want from my join:
Process_Name | Exception_Type | Exception_Reason | 844 | 1550
What I get:
Process_Name | Exception_Type | Exception_Reason | 1308200 | 1308200