2011-04-13 54 views
0

在HP Quality Center 9.2數據庫中,我正在對Oracle 10g - 10.2.0.40進行一些查詢。我可以將2列粘貼到resultSet嗎?

我構建了一個查詢,該查詢將轉到由SIGA鍵給出的測試文件夾,只選擇給定測試文件夾內對該發行版具有正確可跟蹤性的測試。

它也有2個計數器子查詢: TOTAL1總和測試文件夾中的測試總數。 TOTAL2以正確的可追溯性返回測試文件夾中的測試總量。

該查詢工作正常,但有一個缺陷:如果文件夾內沒有任何測試與正確的版本相關聯,則結果集返回空,但即使如此,我希望返回TOTAL1和TOTAL2列,像這樣:

|SIGA| |PROJETO| |ORIGEM|........ |TOTAL1| |TOTAL2| 
|NULL| |NULL| |NULL| ........ |10|  |0| 

那麼,事情是:每次共2爲0時,「主」 ResultSet是空的,因爲它應該,但即使強硬。我希望有共1頁和頁共2列。

即使使用空的resultSet,是否可以將TOTAL1和TOTAL2的新列「粘合」到主查詢中?我試圖讓左連接,但沒有工作。

謝謝, Cleber。

SELECT 
    '@[email protected]'     AS SIGA, 
    CYCL_FOLD.CF_ITEM_NAME AS Projeto, 
    CYCLE.CY_CYCLE   AS Origem, 
    REQ_NAMES.PROCESSO  AS Processo, 
    REQ_NAMES.FUNCIONALIDADE AS Funcionalidade, 
    ALL_LISTS.AL_DESCRIPTION AS Cenario, 
    TEST.TS_TEST_ID   AS Test_ID, 
    TESTCYCL.TC_USER_01  AS ID_Cliente, 
    TEST.TS_NAME    AS Nome_do_Caso, 
    TESTCYCL.TC_USER_02  AS Dependencia, 
    TEST.TS_USER_06   AS Tipo_Teste, 
    TEST.TS_USER_02   AS Tipo_Cenario, 
    /* Descricao */ 
    REGEXP_REPLACE(CAST(TEST.TS_DESCRIPTION AS VARCHAR2(4000)), '<[^<]+>', NULL) AS Descricao, 
    /* Pre_Condicao */ 
    REGEXP_REPLACE(CAST(TEST.TS_USER_25 AS VARCHAR2(4000)), '<[^<]+>', NULL) AS Pre_Condicao, 
    /* Resultado_Esperado */ 
    REGEXP_REPLACE(CAST(TEST.TS_USER_26 AS VARCHAR2(4000)), '<[^<]+>', NULL) AS Resultado_Esperado, 
    /* Dados_Necessarios */ 
    REGEXP_REPLACE(CAST(TEST.TS_USER_27 AS VARCHAR2(4000)), '<[^<]+>', NULL) AS Dados_Necessarios, 
    TESTCYCL.TC_USER_04              AS Resp_Execucao, 
    TESTCYCL.TC_STATUS              AS Status, 
    TEST.TS_USER_03               AS Sistemas_Impactados, 
    TEST.TS_USER_05  AS Regressão, 
    TEST.TS_RESPONSIBLE AS Autor_Do_Caso, 
    /* Comentario */ 
    REGEXP_REPLACE(CAST(TEST.TS_DEV_COMMENTS AS VARCHAR2(4000)) , '<[^<]+>', NULL)AS Comentario, 
    TOTAL1.Total_Testes_TestFolder, 
    TOTAL2.Total_Testes_Com_Rastr 
FROM 
    (
     SELECT 
      COUNT(TESTCYCL.TC_TEST_ID) AS Total_Testes_TestFolder 
     FROM 
      CYCLE, 
      CYCL_FOLD, 
      TESTCYCL 
     WHERE 
      TESTCYCL.TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
     AND CYCLE.CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
     AND CYCL_FOLD.CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
    ) 
    TOTAL1, 
    (
     SELECT 
      COUNT(DISTINCT CONCAT(TESTCYCL.TC_TESTCYCL_ID, TESTCYCL.TC_TEST_ID)) AS 
      Total_Testes_Com_Rastr 
     FROM 
      CYCL_FOLD, 
      CYCLE, 
      TESTCYCL, 
      REQ_COVER, 
      REQ_CYCLES, 
      RELEASE_CYCLES 
     WHERE 
      TESTCYCL.TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
     AND cycle.CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
     AND CYCL_FOLD.CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
     AND REQ_COVER.RC_ENTITY_ID = TESTCYCL.TC_TEST_ID 
     AND REQ_COVER.RC_REQ_ID = REQ_CYCLES.RQC_REQ_ID 
     AND REQ_CYCLES.RQC_CYCLE_ID = RELEASE_CYCLES.RCYC_ID 
     AND RELEASE_CYCLES.RCYC_NAME LIKE CONCAT('@[email protected]','%') 
     ORDER BY 
      TESTCYCL.TC_TEST_ID 
    ) 
    TOTAL2, 
    CYCL_FOLD 
LEFT JOIN RELEASE_CYCLES 
ON 
    RELEASE_CYCLES.RCYC_ID = CYCL_FOLD.CF_ASSIGN_RCYC 
LEFT JOIN CYCLE 
ON 
    CYCLE.CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
LEFT JOIN TESTCYCL 
ON 
    TESTCYCL.TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
LEFT JOIN TEST 
ON 
    TEST.TS_TEST_ID = TESTCYCL.TC_TEST_ID 
LEFT JOIN ALL_LISTS 
ON 
    ALL_LISTS.AL_ITEM_ID = TEST.TS_SUBJECT 
INNER JOIN 
    (
     SELECT 
      TESTCYCL.TC_TEST_ID   AS TEST_ID, 
      wm_concat(REQ2.RQ_REQ_NAME) AS Processo, 
      wm_concat(REQ1.RQ_REQ_NAME) AS Funcionalidade 
     FROM 
      CYCL_FOLD 
     LEFT JOIN CYCLE 
     ON 
      CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
     RIGHT JOIN TESTCYCL 
     ON 
      TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
     RIGHT JOIN REQ_COVER 
     ON 
      RC_ENTITY_ID = TESTCYCL.TC_TEST_ID 
     INNER JOIN REQ REQ1 
     ON 
      RC_REQ_ID = REQ1.RQ_REQ_ID 
     INNER JOIN REQ REQ2 
     ON 
      REQ1.RQ_FATHER_ID = REQ2.RQ_REQ_ID 
     INNER JOIN REQ_TYPE 
     ON 
      REQ2.RQ_TYPE_ID = REQ_TYPE.TPR_TYPE_ID 
      AND REQ_TYPE.TPR_NAME = 'Processo' 
     RIGHT JOIN REQ_CYCLES 
     ON 
      RQC_REQ_ID = REQ1.RQ_REQ_ID 
     INNER JOIN RELEASE_CYCLES 
     ON 
      RQC_CYCLE_ID = RELEASE_CYCLES.RCYC_ID 
     AND CF_ASSIGN_RCYC = RELEASE_CYCLES.RCYC_ID 
     WHERE 
      CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
     GROUP BY 
      TESTCYCL.TC_TEST_ID 

     UNION 

     SELECT 
      TESTCYCL.TC_TEST_ID   AS TEST_ID, 
      '' AS Processo, 
      wm_concat(REQ1.RQ_REQ_NAME) AS Funcionalidade 
     FROM 
      CYCL_FOLD 
     LEFT JOIN CYCLE 
     ON 
      CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
     RIGHT JOIN TESTCYCL 
     ON 
      TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
     RIGHT JOIN REQ_COVER 
     ON 
      RC_ENTITY_ID = TESTCYCL.TC_TEST_ID 
     INNER JOIN REQ REQ1 
     ON 
      RC_REQ_ID = REQ1.RQ_REQ_ID 
     INNER JOIN REQ REQ2 
     ON 
      REQ1.RQ_FATHER_ID = REQ2.RQ_REQ_ID 
     INNER JOIN REQ_TYPE 
     ON 
      REQ2.RQ_TYPE_ID = REQ_TYPE.TPR_TYPE_ID 
      AND REQ_TYPE.TPR_NAME <> 'Processo' 
     RIGHT JOIN REQ_CYCLES 
     ON 
      RQC_REQ_ID = REQ1.RQ_REQ_ID 
     INNER JOIN RELEASE_CYCLES 
     ON 
      RQC_CYCLE_ID = RELEASE_CYCLES.RCYC_ID 
     AND CF_ASSIGN_RCYC = RELEASE_CYCLES.RCYC_ID 
     WHERE 
      CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
     GROUP BY 
      TESTCYCL.TC_TEST_ID 
    ) 
    REQ_NAMES 
ON 
    REQ_NAMES.TEST_ID = TEST.TS_TEST_ID 
WHERE 
    CYCL_FOLD.CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
ORDER BY 
    CYCLE.CY_CYCLE, 
    ALL_LISTS.AL_DESCRIPTION, 
    REQ_NAMES.PROCESSO, 
    TEST.TS_TEST_ID 
+4

我覺得上面的查詢替換爲屬於thedailywtf.com .... – Chandu 2011-04-13 02:37:54

+0

我的一個朋友說,他將它發送到那裏,我不知道網站,可能已經=) 今天我發現了一個更好的方法來做到這一點: 'REGEXP_REPLACE(CAST(TEST.TS_DESCRIPTION AS VARCHAR2(4000)),'<[^<]+>',NULL)AS Descricao,' – cbaldan 2011-04-13 13:09:23

+0

thedaily wtf ...大聲笑 – tbone 2011-04-13 14:29:17

回答

0

所以,如果LEFT OUTER JOIN沒你想它可能是你正在尋找一個RIGHT OUTER JOINFULL OUTER JOIN什麼。

+1

bw_üzi,謝謝你花時間。 一位朋友幫我解決了問題,並找到了一個解決方案:一個查詢總是至少有一行,並且所有主查詢都被移動到一個內部查詢中,並帶有'LEFT JOIN' – cbaldan 2011-04-13 19:43:44

0

就像我上面說的,一位朋友幫我找到了解決方案。

由於PROJETO記錄應該永遠存在,我總是有一排我需要返回共1頁及共2條,即使有0測試用正確的可追溯性(這意味着共2 = 0)

那麼,是什麼我需要的是一個查詢和一個子查詢。

第一個查詢將查找PROJETO文件夾,然後LEFT JOIN到具有所有主要的邏輯子查詢,然後用TOTAL1TOTAL2交叉。

那麼,萬一項目文件夾存在,有測試,但其中0有正確的可追溯性,外部查詢將返回我問(甚至更好):

|SIGA| |PROJETO   | |ORIGEM|........ |TOTAL1| |TOTAL2| 
|1234| |1234 - Project X| |NULL |........ |10|  |0| 

我不知道如果我可以這樣調用,但我將其想象爲一個「包裝查詢」:子查詢中返回的所有記錄都會包含我需要的列。

總之,這裏是代碼:

SELECT 
    '@[email protected]'    AS SIGA, 
    CYCL_FOLD.CF_ITEM_NAME AS Projeto, 
    Origem, 
    Processo, 
    Funcionalidade, 
    Cenario, 
    Test_ID, 
    Instancia_Do_Teste, 
    ID_Cliente, 
    Nome_do_Caso, 
    Dependencia, 
    Tipo_Teste, 
    Tipo_Cenario, 
    Descricao, 
    Pre_Condicao, 
    Resultado_Esperado, 
    Dados_Necessarios, 
    Resp_Execucao, 
    Status_Execução_Caso, 
    Sistemas_Impactados_Teste, 
    Regressao, 
    Autor_Do_Caso, 
    Ordem_Dos_Passos, 
    Nome_do_Passo, 
    Descricao_do_Passo, 
    Resultado_Esperado_Passo, 
    Sistemas_Impactado_Passo, 
    Provedor, 
    ST_RUN_ID, 
    Status_Execução_Passo, 
    TOTAL1.Total_Testes_TestFolder, 
    TOTAL2.Total_Testes_Com_Rastr 
FROM 
    CYCL_FOLD 
LEFT JOIN 
    (
     SELECT 
      CYCL_FOLD.CF_ITEM_NAME, 
      '@[email protected]'     AS SIGA, 
      CYCL_FOLD.CF_ITEM_NAME AS Projeto, 
      CYCLE.CY_CYCLE   AS Origem, 
      REQ_NAMES.PROCESSO  AS Processo, 
      REQ_NAMES.FUNCIONALIDADE AS Funcionalidade, 
      ALL_LISTS.AL_DESCRIPTION AS Cenario, 
      TEST.TS_TEST_ID   AS Test_ID, 
      TC_TEST_INSTANCE   AS Instancia_Do_Teste, 
      TESTCYCL.TC_USER_01 AS ID_Cliente, 
      TEST.TS_NAME  AS Nome_do_Caso, 
      TESTCYCL.TC_USER_02 AS Dependencia, 
      TEST.TS_USER_06  AS Tipo_Teste, 
      TEST.TS_USER_02  AS Tipo_Cenario, 
      /* Descricao */ 
      REGEXP_REPLACE(CAST(TEST.TS_DESCRIPTION AS VARCHAR2(4000)), '<[^<]+>', NULL) AS 
      Descricao, 
      /* Pre_Condicao */ 
      REGEXP_REPLACE(CAST(TEST.TS_USER_25 AS VARCHAR2(4000)), '<[^<]+>', NULL) AS 
      Pre_Condicao, 
      /* Resultado_Esperado */ 
      REGEXP_REPLACE(CAST(TEST.TS_USER_26 AS VARCHAR2(4000)), '<[^<]+>', NULL) AS 
      Resultado_Esperado, 
      /* Dados_Necessarios */ 
      REGEXP_REPLACE(CAST(TEST.TS_USER_27 AS VARCHAR2(4000)), '<[^<]+>', NULL) AS 
      Dados_Necessarios, 
      TESTCYCL.TC_USER_04 AS Resp_Execucao, 
      TESTCYCL.TC_STATUS AS Status_Execução_Caso, 
      TEST.TS_USER_03  AS Sistemas_Impactados_Teste, 
      TEST.TS_USER_05  AS Regressao, 
      TEST.TS_RESPONSIBLE AS Autor_Do_Caso, 
      /* Comentario */ 
      REGEXP_REPLACE(CAST(TEST.TS_DEV_COMMENTS AS VARCHAR2(4000)) , '<[^<]+>', NULL)AS 
      Comentario, 
      DESSTEPS.DS_STEP_ORDER AS Ordem_Dos_Passos, 
      DESSTEPS.DS_STEP_NAME AS Nome_do_Passo, 
      /* Descrição do Passo */ 
      REGEXP_REPLACE(CAST(DESSTEPS.DS_DESCRIPTION AS VARCHAR2(4000)), '<[^<]+>', NULL) AS 
      Descricao_do_Passo, 
      /* Resultado Esperado do Passo */ 
      REGEXP_REPLACE(CAST(DESSTEPS.DS_EXPECTED AS VARCHAR2(4000)), '<[^<]+>', NULL) AS 
      Resultado_Esperado_Passo, 
      DESSTEPS.DS_USER_01 AS Sistemas_Impactado_Passo, 
      DESSTEPS.DS_USER_02 AS Provedor, 
      STEP.ST_RUN_ID, 
      STEP.ST_STATUS AS Status_Execução_Passo 
     FROM 
      CYCL_FOLD 
     LEFT JOIN RELEASE_CYCLES 
     ON 
      RELEASE_CYCLES.RCYC_ID = CYCL_FOLD.CF_ASSIGN_RCYC 
     LEFT JOIN CYCLE 
     ON 
      CYCLE.CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
     LEFT JOIN TESTCYCL 
     ON 
      TESTCYCL.TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
     LEFT JOIN TEST 
     ON 
      TEST.TS_TEST_ID = TESTCYCL.TC_TEST_ID 
     LEFT JOIN DESSTEPS 
     ON 
      DESSTEPS.DS_TEST_ID = TEST.TS_TEST_ID 
     LEFT JOIN RUN 
     ON 
      RN_TEST_ID = TEST.TS_TEST_ID 
     AND RN_TESTCYCL_ID = TESTCYCL.TC_TESTCYCL_ID 
     AND RN_CYCLE_ID = CYCLE.CY_CYCLE_ID 
     LEFT JOIN STEP 
     ON 
      ST_TEST_ID = DS_TEST_ID 
     AND ST_DESSTEP_ID = DESSTEPS.DS_ID 
     AND ST_RUN_ID = RN_RUN_ID 
     LEFT JOIN ALL_LISTS 
     ON 
      ALL_LISTS.AL_ITEM_ID = TEST.TS_SUBJECT 
     INNER JOIN 
      (
       SELECT 
        TESTCYCL.TC_TEST_ID   AS TEST_ID, 
        wm_concat(REQ2.RQ_REQ_NAME) AS Processo, 
        wm_concat(REQ1.RQ_REQ_NAME) AS Funcionalidade 
       FROM 
        CYCL_FOLD 
       LEFT JOIN CYCLE 
       ON 
        CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
       RIGHT JOIN TESTCYCL 
       ON 
        TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
       RIGHT JOIN REQ_COVER 
       ON 
        RC_ENTITY_ID = TESTCYCL.TC_TEST_ID 
       INNER JOIN REQ REQ1 
       ON 
        RC_REQ_ID = REQ1.RQ_REQ_ID 
       INNER JOIN REQ REQ2 
       ON 
        REQ1.RQ_FATHER_ID = REQ2.RQ_REQ_ID 
       INNER JOIN REQ_TYPE 
       ON 
        REQ2.RQ_TYPE_ID = REQ_TYPE.TPR_TYPE_ID 
       AND REQ_TYPE.TPR_NAME = 'Processo' 
       RIGHT JOIN REQ_CYCLES 
       ON 
        RQC_REQ_ID = REQ1.RQ_REQ_ID 
       INNER JOIN RELEASE_CYCLES 
       ON 
        RQC_CYCLE_ID = RELEASE_CYCLES.RCYC_ID 
       AND CF_ASSIGN_RCYC = RELEASE_CYCLES.RCYC_ID 
       WHERE 
        CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
       GROUP BY 
        TESTCYCL.TC_TEST_ID 
       UNION 
       SELECT 
        TESTCYCL.TC_TEST_ID   AS TEST_ID, 
        ''       AS Processo, 
        wm_concat(REQ1.RQ_REQ_NAME) AS Funcionalidade 
       FROM 
        CYCL_FOLD 
       LEFT JOIN CYCLE 
       ON 
        CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
       RIGHT JOIN TESTCYCL 
       ON 
        TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
       RIGHT JOIN REQ_COVER 
       ON 
        RC_ENTITY_ID = TESTCYCL.TC_TEST_ID 
       INNER JOIN REQ REQ1 
       ON 
        RC_REQ_ID = REQ1.RQ_REQ_ID 
       INNER JOIN REQ REQ2 
       ON 
        REQ1.RQ_FATHER_ID = REQ2.RQ_REQ_ID 
       INNER JOIN REQ_TYPE 
       ON 
        REQ2.RQ_TYPE_ID = REQ_TYPE.TPR_TYPE_ID 
       AND REQ_TYPE.TPR_NAME <> 'Processo' 
       RIGHT JOIN REQ_CYCLES 
       ON 
        RQC_REQ_ID = REQ1.RQ_REQ_ID 
       INNER JOIN RELEASE_CYCLES 
       ON 
        RQC_CYCLE_ID = RELEASE_CYCLES.RCYC_ID 
       AND CF_ASSIGN_RCYC = RELEASE_CYCLES.RCYC_ID 
       WHERE 
        CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
       GROUP BY 
        TESTCYCL.TC_TEST_ID 
      ) 
      REQ_NAMES 
     ON 
      REQ_NAMES.TEST_ID = TEST.TS_TEST_ID 
     WHERE 
      CYCL_FOLD.CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
     AND 
      (
       RN_RUN_ID IS NULL 
      OR RN_RUN_ID = 
       (
        SELECT 
         MAX(RN_RUN_ID) 
        FROM 
         RUN 
        WHERE 
         RN_TEST_ID = TEST.TS_TEST_ID 
        AND RN_TEST_INSTANCE = TC_TEST_INSTANCE 
       ) 
      ) 
    ) 
    mainQuery 
ON 
    CYCL_FOLD.CF_ITEM_NAME = mainQuery.CF_ITEM_NAME 
CROSS JOIN 
    (
     SELECT 
      COUNT(TESTCYCL.TC_TEST_ID) AS Total_Testes_TestFolder 
     FROM 
      CYCLE, 
      CYCL_FOLD, 
      TESTCYCL 
     WHERE 
      TESTCYCL.TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
     AND CYCLE.CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
     AND CYCL_FOLD.CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
    ) 
    TOTAL1 
CROSS JOIN 
    (
     SELECT 
      COUNT(DISTINCT CONCAT(TESTCYCL.TC_TESTCYCL_ID, TESTCYCL.TC_TEST_ID)) AS 
      Total_Testes_Com_Rastr 
     FROM 
      CYCL_FOLD, 
      CYCLE, 
      TESTCYCL, 
      REQ_COVER, 
      REQ_CYCLES, 
      RELEASE_CYCLES 
     WHERE 
      TESTCYCL.TC_CYCLE_ID = CYCLE.CY_CYCLE_ID 
     AND cycle.CY_FOLDER_ID = CYCL_FOLD.CF_ITEM_ID 
     AND CYCL_FOLD.CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
     AND REQ_COVER.RC_ENTITY_ID = TESTCYCL.TC_TEST_ID 
     AND REQ_COVER.RC_REQ_ID = REQ_CYCLES.RQC_REQ_ID 
     AND REQ_CYCLES.RQC_CYCLE_ID = RELEASE_CYCLES.RCYC_ID 
     AND RELEASE_CYCLES.RCYC_NAME LIKE CONCAT('@[email protected]','%') 
     ORDER BY 
      TESTCYCL.TC_TEST_ID 
    ) 
    TOTAL2 
WHERE 
    CYCL_FOLD.CF_ITEM_NAME LIKE CONCAT('@[email protected]','%') 
ORDER BY 
    Origem, 
    Funcionalidade, 
    Cenario, 
    Test_ID, 
    Instancia_Do_Teste, 
    Ordem_Dos_Passos 
相關問題