2012-08-22 73 views
0

使用下面的查詢我可以看到JIRA中給定日期的所有issueType的問題計數(否)。JIRA:過去x(即30)天的發佈狀態計數

即。

SELECT count(*), STEP.STEP_ID 
    FROM (SELECT STEP_ID, ENTRY_ID 
    FROM OS_CURRENTSTEP 
    WHERE OS_CURRENTSTEP.START_DATE < '<your date>' 
    UNION SELECT STEP_ID, ENTRY_ID 
    FROM OS_HISTORYSTEP 
    WHERE OS_HISTORYSTEP.START_DATE < '<your date>' 
    AND OS_HISTORYSTEP.FINISH_DATE > '<your date>') As STEP, 
    (SELECT changeitem.OLDVALUE AS VAL, changegroup.ISSUEID AS ISSID 
    FROM changegroup, changeitem 
    WHERE changeitem.FIELD = 'Workflow' 
    AND changeitem.GROUPID = changegroup.ID 
    UNION SELECT jiraissue.WORKFLOW_ID AS VAL, jiraissue.id as ISSID 
    FROM jiraissue) As VALID, 
    jiraissue as JI 
    WHERE STEP.ENTRY_ID = VALID.VAL 
    AND VALID.ISSID = JI.id 
AND JI.project = <proj_id> 
    Group By STEP.STEP_ID; 

結果是

Status Count 
open  12 
closed  13 
.....  .... 

我想實現的是這樣的事情居然..where總計數狀態打開和關閉的每一天。在一個月

選擇的日子,一臺

LEFT OUTER JOIN的表得到計數每一天

(左:

Date  COUNT(Open)  COUNT(Closed) 
12-1-2012  12     1 
13-1-2012  14    5 
+0

我寫的JIRA Timecharts插件做這個,但它使用起來相當繁瑣。 – mdoar

+0

謝謝Mdoar,有沒有我可以參考的鏈接?或者可能共享查詢? – JohnFairul

+0

哦,從這個鏈接https://studio.plugins.atlassian.com/wiki/display/TMCT/JIRA+Timecharts+Plugin ..通過任何機會我能夠知道該查詢嗎?謝謝 – JohnFairul

回答

1

一般的策略應該是這樣如果當天沒有條目,那麼外部連接是必要的,你希望它顯示一個零值)。

所以我覺得這是大概你所需要的(不完整和日期函數的語法可能是錯誤的,你的數據庫,但它讓你更接近):

SELECT aDate 
, COALESCE(SUM(CASE WHEN IssueStatus = 'whateverMeansOpen' THEN 1 END,0)) OpenCount 
, COALESCE(SUM(CASE WHEN IssueStatus = 'whateverMeansClosed' THEN 1 END,0)) ClosedCount 
FROM 
(
    SELECT DATEADD(DAY, I, @START_DATE) aDate 
    FROM 
    (
     SELECT number AS I FROM [SomeTableWithAtLeast31Rows] 
     where number between 1 and 31 
    ) Numbers 
    WHERE DATEADD(DAY, I, @START_DATE) < @END_DATE 
) DateTimesInInterval 
LEFT OUTER JOIN 
(
    Put your query here. It needs to output two columns, DateTimeOfIssue and IssueStatus 
) yourHugeQuery ON yourHugeQuery.DateTimeOfIssue BETWEEN aDate and DATEADD(DAY, 1, aDate) 
GROUP BY aDate 
ORDER BY aDate