Jira SQL自定义字段重叠日期范围

时间:2017-09-25 08:35:06

标签: sql jira

我有一项任务是从ISSUES获得重叠日期,这些日期有"计划开始时间"和"计划完成时间"作为自定义字段。 我使用SQL作为JIRA Driver作为插件。 我到目前为止: 自定义字段ID 10100用于计划开始时间
自定义字段ID 10101用于计划完成时间

SELECT
*
FROM ISSUES i

INNER JOIN ISSUECUSTOMFIELDVALUES icv 
on i.ID=icv.ISSUEID 

INNER JOIN ISSUECUSTOMFIELDVALUES icv2 
on icv2.VALUE >= icv.VALUE

INNER JOIN ISSUECUSTOMFIELDVALUES icv3 
on icv2.VALUE <= icv3.VALUE

WHERE (icv.ISSUEID<>icv2.ISSUEID and icv2.CUSTOMFIELDID=10100 
and icv.CUSTOMFIELDID=10100) and (icv2.ISSUEID<>icv3.ISSUEID 
and icv2.CUSTOMFIELDID=10100 and icv3.CUSTOMFIELDID=10101) 
and icv.ISSUEID=icv3.ISSUEID 
and icv2.ISSUEID= (SELECT ID FROM ISSUES where jql='project=project1' LIMIT 1) //This apears to be the problem
and i.jql='project=project1'

它返回一行,但仅在&#34;计划开始时间&#34;和&#34;计划完成时间&#34; 2个问题匹配,我被卡住了。问题是必须将ISSSUEID分配给现有的ISSUE号码,JIRA API规定了这一点。 我将不胜感激任何帮助。

1 个答案:

答案 0 :(得分:0)

我已将问题行更改为使用IN构造而不是=,因为我认为这是您想要的?

但是,实际上并没有比较开始或结束时间。您确保自定义字段标识符(10100和10101)匹配,但不是自定义字段的值匹配...

...
WHERE (
        icv.ISSUEID <> icv2.ISSUEID 
    AND icv2.CUSTOMFIELDID = 10100 
    AND icv.CUSTOMFIELDID = 10100
) 
AND (
        icv2.ISSUEID <> icv3.ISSUEID 
    AND icv2.CUSTOMFIELDID = 10100 
    AND icv3.CUSTOMFIELDID = 10101
) 
AND icv.ISSUEID = icv3.ISSUEID 
AND icv2.ISSUEID IN (
    SELECT ID FROM ISSUES WHERE jql='project=Prakse'
)
AND i.jql='project=Prakse'
...

编辑我想我现在对这个问题有所了解了。以下内容将为您提供存在重叠时间(开始 - 结束)的另一个问题的所有问题:

SELECT
    *
FROM 
    ISSUES i 
        INNER JOIN ISSUECUSTOMFIELDVALUES icv 
            ON i.ID = icv.ISSUEID 
                AND icv.CUSTOMFIELDID = 10100
        INNER JOIN ISSUECUSTOMFIELDVALUES icv2 
            ON i.ID = icv2.ISSUEID
                AND icv2.CUSTOMFIELDID = 10101
    WHERE 
        i.JQL= 'project=project1'
        AND EXISTS (
            SELECT ID FROM ISSUECUSTOMFIELDVALUES icv3 
            WHERE 
                icv3.ISSUEID <> i.ID
                AND icv3.CUSTOMFIELDID IN (10100, 10101)   
                AND icv3.VALUE >= icv.VALUE 
                AND icv3.VALUE <= icv2.VALUE
        )

编辑2 如果JIRA api确实需要对表键进行更具体的引用,那么以下内容可能会有效(我不能在这里访问JIRA - 只是看看什么是合乎逻辑的):

SELECT
    *
FROM 
    ISSUES i 
        INNER JOIN ISSUECUSTOMFIELDVALUES icv 
            ON i.ID = icv.ISSUEID 
                AND icv.CUSTOMFIELDID = 10100
                AND i.JQL = 'project=project1'
        INNER JOIN ISSUECUSTOMFIELDVALUES icv2 
            ON i.ID = icv2.ISSUEID
                AND icv2.CUSTOMFIELDID = 10101
                AND i.JQL = 'project=project1'
    WHERE 
        i.JQL= 'project=project1'
        AND EXISTS (
            SELECT ID FROM ISSUECUSTOMFIELDVALUES icv3 
            WHERE 
                icv3.ISSUEID <> i.ID
                AND icv3.CUSTOMFIELDID IN (10100, 10101)   
                AND icv3.VALUE >= icv.VALUE 
                AND icv3.VALUE <= icv2.VALUE
        )

编辑3 我不确定这是否能解决问题,但我已删除了子选择(exists)语句,转而使用内连接。

SELECT
    i.ID, i.JQL, icv.VALUE AS StartTime, icv2.VALUE AS FinishTime
FROM 
    ISSUES i 
        LEFT JOIN ISSUECUSTOMFIELDVALUES icv 
            ON i.ID = icv.ISSUEID 
                AND icv.CUSTOMFIELDID = 10100
        LEFT JOIN ISSUECUSTOMFIELDVALUES icv2 
            ON i.ID = icv2.ISSUEID
                AND icv2.CUSTOMFIELDID = 10101
        INNER JOIN ISSUECUSTOMFIELDVALUES icv3
            ON i.ID <> icv3.ISSUEID
                AND (icv3.CUSTOMFIELDID = 10100 OR icv3.CUSTOMFIELDID = 10101)   
                AND icv3.VALUE >= icv.VALUE 
                AND icv3.VALUE <= icv2.VALUE 
 WHERE 
     i.JQL= 'project=project1'