0

通过下面的查询,我可以看到给定日期 JIRA 中所有 issueType 的问题计数(无)。

IE。

  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
.....     ....

我想要实现的实际上是这样的..每天打开和关闭状态的总数。

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

1 回答 1

1

一般的策略是这样的:

从一个月内所有天数的表中选择

LEFT OUTER JOIN 每天计数的表

(如果当天没有条目,则需要左外连接,您希望它显示零值)。

所以我认为这大致是您所需要的(不完整且日期函数语法对于您的数据库可能是错误的,但它会让您更接近):

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
于 2012-08-23T15:25:21.703 回答