I'm doing a report for Bug Metrics. Pertain to that I need some customized table but my query doesn't give expected output.
My query gives the output . So, I want the Oustanding column value must be grouped by project but it is calculating the other project value also.
**Current Output**
*********************************************
|Project | Opened | Resolved| Outstanding |
*********************************************
| A | 1 | 0 | 1 |
*********************************************
| A | 2 | 1 | 2 |
*********************************************
| A | 1 | 2 | 1 |
*********************************************
| B | 3 | 2 | 2 |
*********************************************
| B | 2 | 1 | 3 |
*********************************************
I want the output like , the Outstanding value should calculate separately for each project. Like say precisely, When it comes to Project 'B' it should show the only outstanding values belong to it not to add previous projects outstanding values.
**Expected Output**
*********************************************
|Project | Opened | Resolved| Outstanding |
*********************************************
| A | 1 | 0 | 1 |
*********************************************
| A | 2 | 1 | 2 |
*********************************************
| A | 1 | 2 | 1 |
*********************************************
| B | 3 | 2 | 1 |
*********************************************
| B | 2 | 1 | 2 |
*********************************************
1) Column I want to group by - Outstanding
2) Incremental Variable - @runtot
3) Calculation used for Outstanding - (@runtot := (jtb.Opened + @runtot) - jtb.Resolved) AS Outstanding
My query: -
SELECT jtb.Project,jtb.Opened,jtb.Resolved,
(@runtot := (jtb.Opened + @runtot) - jtb.Resolved) AS Outstanding FROM
(SELECT ji.project AS Project_Id,
pr.pname AS Project_Name,
COUNT(DISTINCT(ji.ID)) AS Opened,
COUNT(IF(ji.issuestatus = 5 OR ji.issuestatus = 6,ji.issuestatus,NULL)) AS Resolved
FROM jiraissue ji
LEFT OUTER JOIN priority p ON (p.ID = ji.priority)
LEFT OUTER JOIN project pr ON (ji.project = pr.ID)
GROUP BY ji.project) jtb,
(SELECT @runtot:=0) c
Kindly help me out :)