Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

SQL Query to mimic the results in SprintReport - Solved

Mr A May 26, 2020

Just wanted to share some query on what i've been struggling for a while now, basically i needed to have a query (sql) where i could see information similar to what is shown in the Sprint report, and show some graphics on what was committed at the beginning of each sprint and what was part of a scope change after the sprint was started.

it toke me a while to come up with a solution and finally i found out a way, hope some one else find this use-full in your implementation.

SELECT ji.id AS issueid,
concat(p.pkey, '-', ji.issuenum)::character varying AS IssueKey,
s."ID" AS sprintid,
s."NAME" as SprintName,
to_timestamp((s."START_DATE" / 1000)::double precision) AS SprintStart,
to_timestamp((s."END_DATE" / 1000)::double precision) AS SprintEnd,
to_timestamp((s."COMPLETE_DATE" / 1000)::double precision) AS SprintCompleted,
p.pname as ProjectName,
-- This Here is the tricky part, we have to evaluate two sources of info, ChangeGroup and CustomFieldValue
-- If ChangeGroup returns null (probably bc the issue was created directly into the sprint)
-- Then we have to Search in the customFieldValue.created value (sprint fieldId is 10001 in my implementation)
COALESCE((SELECT cg.created
FROM Changegroup cg -- Searching the changegroup/change itme tables
INNER JOIN ChangeItem ci on ci.groupid = cg.id AND ci.field = 'Sprint'
WHERE cg.issueid = ji.id
AND ci.newvalue ~ s."ID"::text
AND NOT COALESCE(ci.oldvalue,'') ~ s."ID"::text
ORDER BY cg.id
LIMIT 1),
(SELECT TO_TIMESTAMP(cfv.updated/1000) --if null was returned from the previous query then we just search the
-- value in the customfieldvalue.updated
FROM customfieldvalue cfv
WHERE cfv.issue = ji.id AND cfv.customfield=10001::numeric
AND cfv.stringvalue::bigint = s."ID"
LIMIT 1)) AS AddedToSprintDate
FROM jiraissue ji
JOIN project p ON ji.project = p.id
JOIN nodeassociation na ON p.id = na.source_node_id AND na.sink_node_entity::text = 'ProjectCategory'::text
JOIN customfieldvalue cfv ON cfv.issue = ji.id
JOIN "AO_60DB71_SPRINT" s ON cfv.customfield = 10001::numeric AND s."ID" = cfv.stringvalue::bigint
JOIN issuetype it ON ji.issuetype::text = it.id::text
WHERE it.pname::text = 'Story'::text
AND s."ID" = 3169 --Finally filter by the sprintid you want the report from
ORDER BY s."ID";

1 comment

ERIK SERGIO SOLIS CAMACHO May 26, 2020

this is awesome !!! it worked for me and I exported the data to chamostudio.

 

well done

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events