Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform arithmetic operation on the outputs of 2 queries

Below are 2 queries:

SELECT COUNT(BUG.BG_BUG_ID) AS BUG_ID_SIT_CNT 
FROM BUG 
WHERE BUG.BG_USER_02 = 'SIT'

SELECT COUNT(BUG.BG_BUG_ID) AS BUG_ID_UAT_CNT 
FROM BUG 
WHERE BUG.BG_USER_02 = 'UAT'

How to write a query to use the results from the above queries and perform the below operation:

Defect Removal Efficiency: BUG_ID_SIT_CNT/(BUG_ID_SIT_CNT + BUG_ID_UAT_CNT)

like image 325
Jayanth Srivastav Avatar asked Jan 06 '23 18:01

Jayanth Srivastav


1 Answers

SELECT BUG_ID_SIT_CNT * 1. / BUG_ID_ALL
FROM (
    SELECT
        COUNT(CASE WHEN BG_USER_02 = 'SIT' THEN BG_BUG_ID END) AS BUG_ID_SIT_CNT,
        COUNT(BG_BUG_ID) AS BUG_ID_ALL
    FROM BUG
    WHERE BG_USER_02 IN ('SIT', 'UAT')
) t
like image 133
Devart Avatar answered Jan 10 '23 15:01

Devart