SQL查询可为打开的错误创建老化报告

时间:2019-04-06 18:56:33

标签: mysql sql

我正在为每个季度为“ 30-60天”,“ 60-90天”,“ 3-6个月”和“ 6个月以上”打开的错误创建老化报告。如果错误是在Q-1中创建的,但在Q-2中仍处于打开状态,并且满足上述条件,则应将其计入上述Q-2的存储桶中

select Category,
       SUM(CASE WHEN Bugs_open_days > 29 and Bugs_open_days < 61 THEN 1 ELSE 0 END) as bucket_30_60,
       SUM(CASE WHEN Bugs_open_days > 60 and Bugs_open_days < 91 THEN 1 ELSE 0 END) as bucket_60_90,
       SUM(CASE WHEN Bugs_open_days > 90 and Bugs_open_days < 181 THEN 1 ELSE 0 END) as bucket_3_6,
       SUM(CASE WHEN Bugs_open_days >= 181 THEN 1 ELSE 0 END) as bucket_6monthplus
from (
select Created_Quarter,
       Category,
       bug_id,
       Resolved_Count_In_Days,
       Resolved_Count_In_Days - 1 as Bugs_open_days
from TableA)
group by 1

On Date Category 30-60 days 60-90 days  3-6 months  6+ months
2018-03-31 P       0                             0   0  
2018-03-31 G       6          5              0       0
2018-03-31 W       4         10              0       0
2018-03-31 GM      16        12              0       0
2018-03-31 null    3          2              0       0
2018-06-30                  
2018-06-30                  
2018-06-30                  
2018-06-30                  
2018-06-30                  
2018-06-30                  
2018-09-30                  
2018-09-30                  
2018-09-30                  
2018-09-30                  
2018-09-30                  
2018-09-30                  
2018-12-31                  
2018-12-31                  
2018-12-31                  
2018-12-31                  
2018-12-31                  
2018-12-31                  
2019-03-31                  
2019-03-31                  
2019-03-31                  
2019-03-31                  
2019-03-31                  
2019-03-31

0 个答案:

没有答案