2015-10-21 74 views
-1

下面的查詢用於從ALM中獲取阻塞測試用例的數量。是否可以在CASE語句中包含此查詢,以使CASE語句的輸出爲「COUNT(LINK.LN_ENTITY_ID)」?將子查詢包含到SQL CASE語句中

SELECT BUG.BG_BUG_ID, COUNT(LINK.LN_ENTITY_ID) AS COUNT_TC, TESTCYCL.TC_STATUS FROM BUG 
LEFT JOIN ALL_LISTS 
ON BG_SUBJECT = AL_ITEM_ID 
INNER JOIN LINK 
ON BG_BUG_ID = LN_BUG_ID 
LEFT JOIN TESTCYCL 
ON TESTCYCL.TC_TEST_ID = LINK.LN_ENTITY_ID AND LINK.LN_ENTITY_TYPE = 'TESTCYCL' 
WHERE TESTCYCL.TC_STATUS = 'Blocked' 
GROUP BY BG_BUG_ID, TESTCYCL.TC_STATUS 
+0

請註明表結構 –

回答

0
SELECT BUG.BG_BUG_ID, 
     SUM(CASE TESTCYCL.TC_STATUS WHEN ="Blocked" THEN 1 ELSE 0 END) AS COUNT_TC, 
     TESTCYCL.TC_STATUS 
    FROM BUG 
    LEFT JOIN ALL_LISTS 
    ON BG_SUBJECT = AL_ITEM_ID 
    INNER JOIN LINK 
    ON BG_BUG_ID = LN_BUG_ID 
    LEFT JOIN TESTCYCL 
    ON TESTCYCL.TC_TEST_ID = LINK.LN_ENTITY_ID AND LINK.LN_ENTITY_TYPE = 'TESTCYCL' 
    GROUP BY BG_BUG_ID 

這個查詢將顯示總無。狀態= "blocked",每個BUG_ID(假設你需要)。

希望這會有幫助