针对JIRA问题的SQL查询

时间:2015-03-12 09:24:24

标签: sql database oracle11g jira

我必须从JIRA数据库中获取一些数据并创建一个视图来显示它们。

在我们的JIRA中,我们有大约100个项目。我们需要创建一个Oracle视图来可视化以下数据。

我们的工作流程具有以下状态     打开     固定     解决     测试     验证     关闭     拒绝

For a single project, if issues are Delivery-CR, Fault-Bug, Fault-Specification, Fault-Configuration or Fault-Testing we need to create a view to visualize following data.

•   transition date – open to fix
•   transition date – fix to resolved
•   transition date – resolved to test
•   transition date – test to validate
•   Issue type
•   Status 
•   Fix version

Note that Issue type, Status and Fix version are on CHANGEITEM table. I can't find a table to get transaction dates. 

We are using JIRA 6.3.7 and Oracle 11g database

我尝试过以下查询,但没有成功。

select created, issueid, ci.oldstring, ci.newstring, ci.oldvalue, ci.newvalue from changegroup inner join changeitem ci on changegroup.ID = ci.groupid where issueid in (select ID from JIRAISSUE where PROJECT in (select ID from PROJECT where PNAME = 'Singapore Exchange Post Trade') and ISSUETYPE in (select ID from ISSUETYPE where PNAME in ('Delivery-CR', 'Fault-Bug', 'Fault-Specification', 'Fault-Configuration', 'Fault-Testing'))) where ci.oldstring in('Open','Fix','Resolved','Test','Validate','Closed','Rejected');

有人可以告诉我哪里出错了。

2 个答案:

答案 0 :(得分:1)

我想你想每行有一个问题。

这份报告不是一件容易的事,JIRA数据库结构中有一些因素会导致这种情况变慢。

我已经构建了一个查询,通过重新加入相同的表来连接列,以获得不同的兴趣值。您可以通过重复CH_n左连接(“CHange”)来添加列。

WITH JIRAISSUE_W AS (
    SELECT
      JI.ID                                ,
      P.PKEY ||'-' || JI.ISSUENUM AS "KEY",
      IT.PNAME  AS ISSUETYPE                ,
      IST.PNAME AS ISSUESTATUS              ,
      CG.ISSUEID                            ,
      CG.AUTHOR                             AS "WHO",
      CG.CREATED                            AS "WHEN",
      CI.FIELD                              AS "WHAT",
      DBMS_LOB.SUBSTR(CI.OLDSTRING, 256, 1) AS "FROM",
      DBMS_LOB.SUBSTR(CI.NEWSTRING, 256, 1) AS "TO"
    FROM JIRAISSUE JI
    INNER JOIN ISSUESTATUS IST ON IST.ID = JI.ISSUESTATUS
    INNER JOIN PROJECT P ON P.ID = JI.PROJECT
    INNER JOIN ISSUETYPE IT ON JI.ISSUETYPE = IT.ID
    LEFT JOIN CHANGEGROUP CG ON CG.ISSUEID = JI.ID
    INNER JOIN CHANGEITEM CI ON CI.GROUPID = CG.ID
    WHERE IT.PNAME IN ('Delivery-CR', 'Fault-Bug', 'Fault-Specification',
                       'Fault-Configuration', 'Fault-Testing')
    ORDER BY JI.CREATED
  )
SELECT
  CH_1.KEY                   ,
  CH_1.ISSUETYPE             ,
  CH_1.ISSUESTATUS           ,
  FIXV."TO"   AS FIXVERSION  ,
  CH_1."WHEN" AS "TO_FIX"    ,
  CH_2."WHEN" AS "TO_RESOLVE",
  CH_3."WHEN" AS "TO_TEST"   ,
  CH_4."WHEN" AS "TO_VALIDATE"
FROM JIRAISSUE_W CH_1
LEFT JOIN JIRAISSUE_W FIXV ON 
  FIXV.ISSUEID = CH_1.ID AND 
  FIXV."WHAT"  = 'Fix Version'
LEFT JOIN JIRAISSUE_W CH_2 ON
  CH_2.ISSUEID = CH_1.ID AND
  CH_2."WHAT"  = 'status' AND
  CH_2."TO"    = 'Resolved'
LEFT JOIN JIRAISSUE_W CH_3 ON
  CH_3.ISSUEID = CH_1.ID AND
  CH_3."WHAT"  = 'status' AND
  CH_3."TO"    = 'Test'
LEFT JOIN JIRAISSUE_W CH_4 ON
  CH_4.ISSUEID = CH_1.ID AND
  CH_4."WHAT"  = 'status' AND
  CH_4."TO"    = 'Validated'
WHERE
  CH_1."WHAT" = 'status' AND
  CH_1."TO"   = 'Fix';

一小时内不是最好的,但你可以为初学者提供这个。

答案 1 :(得分:1)

我的任务是在Jira中重新创建转换视图,并认为我的解决方案可能对您的问题有所帮助。

我们正在使用Postgres,所以我猜你需要改变年龄函数。 这表现得非常好:

select 
                ci.oldstring        as OldStatus
                , ci.newstring as NewStatus
                , AGE(cg.created, coalesce (LEAD (cg.created, -1) OVER closedTime, ji.created)) AS age 
                , cg.created as TransitionCreated
                , ji.created as IssueCreated
                , proj.pname as ProjectName
                , ji.id as IssueId
                , ji.summary
                , ji.reporter
                , ji.assignee
from jiraissue ji
JOIN project proj on ji.project = proj.id
join changegroup cg ON ji.id= cg.issueId
JOIN changeItem ci 
                on cg.id = ci.groupId 
                and ci.field = 'status'
WINDOW
                closedTime AS (PARTITION BY cg.issueId order by cg.id)
order by cg.issueid, cg.id