0

我在嘗試在HP Quality Center中運行SQL查詢時收到錯誤消息。該消息是「因爲它包含無效的報表質量中心無法運行查詢的數據庫是Oracle我的查詢是:HP Quality Center中的「WITH」SQL語句 - 無效的語句 - Oracle DB

WITH AUDIT AS 
(
SELECT AUDIT_LOG.AU_ENTITY_ID AS DEFECT_ID, 
     MIN(AUDIT_LOG.AU_TIME) AS Date_Deferred, 
     AUDIT_LOG.AU_USER AS UserName_Deferred 
FROM AUDIT_LOG 
INNER JOIN AUDIT_PROPERTIES 
ON AUDIT_LOG.AU_ACTION_ID = AUDIT_PROPERTIES.AP_ACTION_ID 
WHERE AUDIT_LOG.AU_ENTITY_TYPE = 'BUG' 
    AND AUDIT_LOG.AU_ACTION = 'UPDATE' 
    AND AUDIT_PROPERTIES.AP_TABLE_NAME = 'BUG' 
    AND AUDIT_PROPERTIES.AP_FIELD_NAME = 'BG_STATUS' 
    AND AUDIT_PROPERTIES.AP_NEW_VALUE = 'Deferred' 
GROUP BY 
    AUDIT_LOG.AU_ENTITY_ID,AUDIT_LOG.AU_USER 
), 

WITH BUG_LIST AS 
(
SELECT BUG.BG_BUG_ID/*Defect.Defect ID*/, BUG.BG_DETECTION_DATE /*Defect.Detected on Date*/, BUG.BG_USER_01 /*Defect.Application*/, BUG.BG_SEVERITY /*Defect.Severity*/, BUG.BG_STATUS /*Defect.Status*/, BUG.BG_USER_11 /*Defect.Planned Closing Date*/, BUG.BG_DETECTED_BY /*Defect.Detected By*/ 
FROM BUG /*Defect*/ 
WHERE BUG.BG_USER_17 /*Defect.Finding Group*/ = 'UAT' 
ORDER BY BUG.BG_DETECTION_DATE ASC 
) 

SELECT * 
FROM BUG_LIST 
INNER JOIN AUDIT ON AUDIT.DEFECT_ID = BUG_LIST.BG_BUG_ID 

‘審覈’查詢尋找有QC任何錯誤,在某些時候,其狀態更改爲「延遲」,其中包含使用HPQC的所有團隊的錯誤,「BUG_LIST」查詢專門查找由「UAT」組發現的錯誤,我可以單獨運行每個查詢並嘗試合併如果UAT發現的錯誤與它有關聯的延遲日期狀態改變,則顯示該信息,如果沒有,則將該信息留空以用於特定缺陷

我在的原因誘惑這是因爲任何進入「延期」狀態的錯誤都沒有像計劃關閉的錯誤那樣的「計劃關閉日期」。因此,我希望看到錯誤進入延期狀態的日期,並認爲我的「關閉日期」。

HPQC是否不支持「WITH」語句?有什麼方法可以成功結合並運行這些查詢嗎?

+0

我相信WITH出現在9i。 – EvilTeach

回答

1

你只需要with出現一次,所以刪除with前BUG_LIST:

WITH AUDIT AS 
(
SELECT 
AUDIT_LOG.AU_ENTITY_ID AS DEFECT_ID, 
MIN(AUDIT_LOG.AU_TIME) AS Date_Deferred, 
AUDIT_LOG.AU_USER AS UserName_Deferred 
FROM AUDIT_LOG 
INNER JOIN AUDIT_PROPERTIES 
ON AUDIT_LOG.AU_ACTION_ID = AUDIT_PROPERTIES.AP_ACTION_ID 
WHERE AUDIT_LOG.AU_ENTITY_TYPE = 'BUG' AND AUDIT_LOG.AU_ACTION = 'UPDATE' AND AUDIT_PROPERTIES.AP_TABLE_NAME = 'BUG' AND AUDIT_PROPERTIES.AP_FIELD_NAME = 'BG_STATUS' AND AUDIT_PROPERTIES.AP_NEW_VALUE = 'Deferred' 
GROUP BY 
AUDIT_LOG.AU_ENTITY_ID,AUDIT_LOG.AU_USER 
), 

    BUG_LIST AS 
(
SELECT BUG.BG_BUG_ID/*Defect.Defect ID*/, BUG.BG_DETECTION_DATE /*Defect.Detected on Date*/, BUG.BG_USER_01 /*Defect.Application*/, BUG.BG_SEVERITY /*Defect.Severity*/, BUG.BG_STATUS /*Defect.Status*/, BUG.BG_USER_11 /*Defect.Planned Closing Date*/, BUG.BG_DETECTED_BY /*Defect.Detected By*/ 
FROM BUG /*Defect*/ 
WHERE BUG.BG_USER_17 /*Defect.Finding Group*/ = 'UAT' 
ORDER BY BUG.BG_DETECTION_DATE ASC 
) 

SELECT * 
FROM BUG_LIST 
INNER JOIN AUDIT ON AUDIT.DEFECT_ID = BUG_LIST.BG_BUG_ID 

您可以隨時將這些成一個單一的from using語句子查詢:

select * 
from (your bug_list query here) bl inner join 
    (your audit query here) a 
    on a.defect_id = bl.bd_bug_id 
+0

我在想同樣的事情,但我更新了它,仍然收到相同的錯誤。任何其他想法? – pkracer

+0

人們會注意到,除了使查詢運行更長以外,BUG_LIST中的順序沒有任何效果。 – EvilTeach

+0

@EvilTeach。 。 。它是否運行更長取決於SQL引擎。在許多情況下,子查詢中的'order by'被忽略。 –

0

WITH通常用於允許您重複使用中的一個,其中有條款。在這種情況下,它不是必需的,所以查詢可以被重寫成這樣。 (我不能測試這個)

SELECT audit.*, bug_list.* 
FROM 
(
    SELECT BUG.BG_BUG_ID/*Defect.Defect ID*/, 
      BUG.BG_DETECTION_DATE /*Defect.Detected on Date*/, 
      BUG.BG_USER_01 /*Defect.Application*/, 
      BUG.BG_SEVERITY /*Defect.Severity*/, 
      BUG.BG_STATUS /*Defect.Status*/, 
      BUG.BG_USER_11 /*Defect.Planned Closing Date*/, 
      BUG.BG_DETECTED_BY /*Defect.Detected By*/ 
    FROM BUG /*Defect*/ 
    WHERE BUG.BG_USER_17 /*Defect.Finding Group*/ = 'UAT' 
) BUG_LIST, 
(
    SELECT AUDIT_LOG.AU_ENTITY_ID AS DEFECT_ID, 
      MIN(AUDIT_LOG.AU_TIME) AS Date_Deferred, 
      AUDIT_LOG.AU_USER AS UserName_Deferred 
    FROM AUDIT_LOG 
    INNER JOIN AUDIT_PROPERTIES 
    ON AUDIT_LOG.AU_ACTION_ID = AUDIT_PROPERTIES.AP_ACTION_ID 
    WHERE AUDIT_LOG.AU_ENTITY_TYPE = 'BUG' 
     AND AUDIT_LOG.AU_ACTION = 'UPDATE' 
     AND AUDIT_PROPERTIES.AP_TABLE_NAME = 'BUG' 
     AND AUDIT_PROPERTIES.AP_FIELD_NAME = 'BG_STATUS' 
     AND AUDIT_PROPERTIES.AP_NEW_VALUE = 'Deferred' 
    GROUP BY 
     AUDIT_LOG.AU_ENTITY_ID,AUDIT_LOG.AU_USER 
) AUDIT 
INNER JOIN AUDIT 
ON AUDIT.DEFECT_ID = BUG_LIST.BG_BUG_ID 
ORDER BY BUG_list.BG_DETECTION_DATE ASC 
+0

感謝您的反饋。查詢以不同的錯誤運行。 「ORA-00936:缺少表達。」 – pkracer