Quantcast
Channel: All Quality Center / ALM Practitioners Forum posts
Viewing all articles
Browse latest Browse all 14708

Re: Need help with SQL to pull daily counts (# of defects opened, resolved, closed, etc. on daily ba

$
0
0

Try this one.

 

Select AP_NEW_VALUE As "Status", count(TOTAL_BUGS) As "Weekly Defects", Sum(D1) As "Day 1", Sum(D2) As "Day 2", Sum(D3) As "Day 3", Sum(D4) As "Day 4", Sum(D5) As "Day 5", Sum(D6) As "Day 6", Sum(D7) As "Day 7" FROM (
SELECT AP_NEW_VALUE, count(BG_BUG_ID) TOTAL_BUGS,
sum( case when datediff(DAY, AU_TIME, getdate()) <= 1 then 1 else 0 end) D1,
sum( case when datediff(DAY, AU_TIME, getdate()) <= 2 and datediff(DAY, AU_TIME, getdate()) > 1 then 1 else 0 end) D2,
sum( case when datediff(DAY, AU_TIME, getdate()) <= 3 and datediff(DAY, AU_TIME, getdate()) > 2 then 1 else 0 end) D3,
sum( case when datediff(DAY, AU_TIME, getdate()) <= 4 and datediff(DAY, AU_TIME, getdate()) > 3 then 1 else 0 end) D4,
sum( case when datediff(DAY, AU_TIME, getdate()) <= 5 and datediff(DAY, AU_TIME, getdate()) > 4 then 1 else 0 end) D5,
sum( case when datediff(DAY, AU_TIME, getdate()) <= 6 and datediff(DAY, AU_TIME, getdate()) > 5 then 1 else 0 end) D6,
sum( case when datediff(DAY, AU_TIME, getdate()) <= 7 and datediff(DAY, AU_TIME, getdate()) > 6 then 1 else 0 end) D7
FROM BUG
INNER JOIN AUDIT_LOG on AU_ENTITY_ID = BG_BUG_ID and AU_ENTITY_TYPE='BUG' and AU_ACTION='UPDATE'
INNER JOIN AUDIT_PROPERTIES on AP_ACTION_ID = AU_ACTION_ID and AP_FIELD_NAME = 'BG_STATUS'
INNER JOIN (
            SELECT MAX(AU_TIME) MY_TIME, AU_ENTITY_ID MY_BUG_ID FROM AUDIT_LOG
            INNER JOIN AUDIT_PROPERTIES on AP_ACTION_ID = AU_ACTION_ID and AP_FIELD_NAME = 'BG_STATUS' and AU_ENTITY_TYPE='BUG'              and AU_ACTION='UPDATE'
            GROUP BY CONVERT(VARCHAR,AU_TIME,101), AU_ENTITY_ID
            ) IJ on MY_TIME = AU_TIME and MY_BUG_ID = BG_BUG_ID
WHERE datediff(DAY, AU_TIME, getdate()) <= 7
GROUP BY AP_NEW_VALUE, AU_TIME
) MAP
GROUP BY AP_NEW_VALUE

 


Viewing all articles
Browse latest Browse all 14708

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>