我正在HP Quality Center 9.2数据库中处理有关Oracle 10g - 10.2.0.40的一些查询。
我构建了一个查询,该查询将转到SIGA密钥给出的测试文件夹,只选择给定测试文件夹中对该版本具有正确可追溯性的测试。
它还有2个计数器子查询: TOTAL1总计测试文件夹中的测试总数。 TOTAL2以正确的可追溯性返回测试文件夹中的测试总量。
查询工作正常,但有一个缺陷:如果文件夹中没有任何测试与正确的版本相关联,结果集将返回空,但即使如此,我希望返回TOTAL1和TOTAL2列,像这样:
|SIGA| |PROJETO| |ORIGEM|........ |TOTAL1| |TOTAL2|
|NULL| |NULL| |NULL| ........ |10| |0|
所以,事情是:每次TOTAL2为0时,“main”resultSet都是空的,应该如此,但即使很难,我也希望有TOTAL1和TOTAL2列。
即使使用空的resultSet,是否可以将带有TOTAL1和TOTAL2的新列“粘合”到主查询?我试图让LEFT JOIN但是没有用。
谢谢, 克莱伯。
SELECT
'@SIGA@' 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('@SIGA@','%')
)
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('@SIGA@','%')
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('@SIGA@','%')
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('@SIGA@','%')
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('@SIGA@','%')
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('@SIGA@','%')
ORDER BY
CYCLE.CY_CYCLE,
ALL_LISTS.AL_DESCRIPTION,
REQ_NAMES.PROCESSO,
TEST.TS_TEST_ID
答案 0 :(得分:0)
因此,如果LEFT OUTER JOIN
没有达到您想要的效果,那么您可能正在寻找RIGHT OUTER JOIN
或FULL OUTER JOIN
。
答案 1 :(得分:0)
就像我上面所说,一位朋友帮我找到了解决方案。
由于PROJETO
记录应该始终存在,所以我总是需要返回TOTAL1和TOTAL2的一行,即使有0个测试具有正确的可追溯性(这意味着TOTAL2 = 0)
所以,我需要的是一个查询和一个子查询。
第一个查询将查找PROJETO
文件夹,然后LEFT JOIN
查找包含所有主要逻辑的子查询,然后查找包含TOTAL1
和TOTAL2
的CROSS。
所以,如果项目文件夹存在,有测试,但其中0个具有正确的可追溯性,外部查询将返回我的要求(甚至更好):
|SIGA| |PROJETO | |ORIGEM|........ |TOTAL1| |TOTAL2|
|1234| |1234 - Project X| |NULL |........ |10| |0|
我不确定我是否可以这样调用,但我想这是一个“包装查询”:子查询中返回的所有记录都包含了我需要的列。
无论如何,这是代码:
SELECT
'@SIGA@' 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,
'@SIGA@' 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('@SIGA@','%')
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('@SIGA@','%')
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('@SIGA@','%')
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('@SIGA@','%')
)
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('@SIGA@','%')
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('@SIGA@','%')
ORDER BY
TESTCYCL.TC_TEST_ID
)
TOTAL2
WHERE
CYCL_FOLD.CF_ITEM_NAME LIKE CONCAT('@SIGA@','%')
ORDER BY
Origem,
Funcionalidade,
Cenario,
Test_ID,
Instancia_Do_Teste,
Ordem_Dos_Passos