I have a database table called JOBS which has ID,STATUS and COMPLETION_TIME as the columns. STATUS 0,1 is success, STATUS 2,3 is fail and STATUS 4,5 is killed. It can have only one status. I want to find number of jobs that succeeded , failed and killed within last 10 hours. I have to use only SELECT for the query and cannot any variables for the query. I used following query for the operation.
SELECT
(SELECT COUNT(*)
WHERE STATUS IN (0,1))AS SuccessCount,
(SELECT COUNT(*)
WHERE STATUS IN (2,3))AS FailedCount ,
(SELECT COUNT(*)
WHERE STATUS IN (4,5))AS KilledCount,
FROM JOBS
WHERE COMPLETION_TIME >= (SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE()) - (10 * 60 * 60))
AND COMPLETION_TIME <= (SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE()));
But this query is not working. It is giving me jobs which succeeded, failed or killed and not their number.