JIRA SQL: find average time in status X in

Adolfo Casari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2014

Hi,

I am trying to build a sql query (postgres) that will return the average time issues spent in status X given a timefrime (for instance in current month).

Has anyone tried this?

Thanks in advance.

4 answers

1 accepted

0 votes
Answer accepted
Adolfo Casari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2014

I found was I was looking for here:

https://answers.atlassian.com/questions/66047

After some minor changes for POSTGRES it shows the same info you get in the Transition tabs for the issue, i.e., Time in Status. Then I had to average it over all issues for each state.

Robert Oliveira July 4, 2019

Hi, can you share the settings you made to work in postgree? Thank you very much in advance.

1 vote
Jarrod Moura February 20, 2020

For those looking for the answer in SQL, here it is:

WITH statusHistory AS
(select
jiraissue.ID, changeitem.OLDSTRING OldStatus, changeitem.NEWSTRING NewStatus, changegroup.CREATED Executed,
DATEDIFF(minute, changegroup.CREATED, Lead(changegroup.CREATED) OVER (Partition By jiraissue.ID ORDER BY changegroup.CREATED)) MinutesInStatus,
ROW_NUMBER() OVER (Partition By jiraissue.ID order by changegroup.CREATED) StatusOrder
from changeitem (nolock)
inner join changegroup (nolock) on changeitem.groupid = changegroup.id
inner join jiraissue (nolock) on jiraissue.id = changegroup.issueid
where
changeitem.field ='status'
)

select ID, OldStatus, NewStatus, Executed, ISNULL(MinutesInStatus, DATEDIFF(minute, Executed, GETDATE())) MinutesInStatus, StatusOrder
from statusHistory

0 votes
deepali3031 June 25, 2020

For those looking for postgres query, This will give you Time in status 

WITH statusHistory AS
(select
jiraissue.ID, p.pname, p.pkey, jiraissue.issuenum, jiraissue.priority, pri.pname as priorityname, c.cname as componentname, pv.id as fixversionId, pv.vname as fixversion, jiraissue.created as issueCreated, jiraissue.resolutiondate, changeitem.OLDSTRING OldStatus, changeitem.NEWSTRING NewStatus, changegroup.CREATED Executed,
changegroup.CREATED - lag(changegroup.CREATED) over (PARTITION BY jiraissue.ID order by changegroup.CREATED) as MinutesInStatus,
ROW_NUMBER() OVER (Partition By jiraissue.ID order by changegroup.CREATED) StatusOrder
from changeitem
inner join changegroup on changeitem.groupid = changegroup.id
inner join jiraissue on jiraissue.id = changegroup.issueid
inner join project p on jiraissue.project = p.id
inner join nodeassociation na on na.SOURCE_NODE_ID = jiraissue.ID
inner join projectversion pv on pv.id = na.SINK_NODE_ID
join priority pri on pri.id = jiraissue.priority
inner join component c on na.sink_node_id = c.id
where
changeitem.field ='status' AND changeitem.FIELDTYPE='jira' And pkey = 'HM'
)

Select * From statusHistory

0 votes
Zubaidullou December 11, 2014

Hi Adolfo,

I have tried this logic, but not from DB, I tried getting data from JIRA server by JIRA REST Java Client on JIRA has jql you can use it.

 

Suggest an answer

Log in or Sign up to answer