查询:特定测试的问题计数(时间点快照)

时间:2019-07-17 19:06:08

标签: mysql

我正在尝试查询过去发生的测试问题的数量。作为背景,每年进行一次测试。为每个测试中出现的每个“问题”创建一个记录。一个测试可能有0到许多问题。测试完成后,这些问题不再存在时,可以加班关闭。每个问题都具有“当前”状态。还有一个用于跟踪问题状态更改的表,例如审核日志。明年到来时,测试将包括以前所有未解决的问题和未解决的其他问题。查找每年在特定测试中打开多少个问题的正确查询是什么?

即:

  • 2018年有9期。 1个加班时间关闭。
  • 2019年发行了3期新刊物,还有8种自2018年起仍开放。

预期的查询结果将显示2018年的9期和2019年的11期。

下面的查询是我到目前为止所拥有的。

表的关系如下。

  • 参与-有一个应用程序
  • 问题-一个应用程序可能有很多问题
  • 状态更改-一个问题可以有许多状态更改
    SELECT *
        COUNT(*) as totalissues,              
        SUM(CASE WHEN issues.issue_type IN('EAPT','ENPT','ENVS') THEN 1 ELSE 0 
    end) AS externalissues,
        SUM(CASE WHEN issues.issue_type IN('IAPT','INPT','INVS') THEN 1 ELSE 0 
    end) AS internalissues     
         FROM engagements
         LEFT OUTER JOIN issues ON engagements.application_id = issues.application_id                   
         LEFT OUTER JOIN status_change sc1 ON issues.id = sc1.issue_id AND issues.engagement_id != engagements.engagement_id AND date(sc1.change_date) < date(engagements.end_date)           
         WHERE
            engagements.engagement_id = 'APT_ItemProcessingOutsourcing_DLM_2018_07'
            AND (       
            sc1.id is null                 
                or (                        
                   sc1.id = (
                       SELECT max(sc2.id)                                              
                       FROM engagements e2                                
                       LEFT OUTER JOIN issues i2 ON e2.application_id = i2.application_id                                
                       LEFT OUTER JOIN status_change sc2 ON                                 i2.id = sc2.issue_id                                     
                       AND date(sc2.change_date) < date(e2.end_date)                                
                       WHERE                                    
                       sc1.issue_id = sc2.issue_id                                   
                       AND sc2.change_date = (                                       
                             SELECT max(sc3.change_date)                                         
                             FROM status_change sc3                                                          
                             WHERE sc3.issue_id = sc2.issue_id                               
                             AND sc3.change_date <= date(e2.end_date)
                                )
                        )
                )
            AND sc1.new_status not in(4,8,9,10)
        );

此查询有6个问题,我希望有9个。如果您需要更多信息,请告诉我。

Status change Table 
id  old_status  new_status  change_date issue_id    user_id comment_id
40748721    10  1   7/18/2017 15:09 14440592    64  NULL
67384812    1   3   7/26/2018 16:43 14440592    26  13023597
67384814    7   4   7/26/2018 16:44 14440592    26  13023599
67384813    3   7   7/26/2018 16:43 14440592    26  13023598
40748722    10  1   7/18/2017 15:09 14440593    64  NULL
40748724    10  1   7/18/2017 15:09 14440595    64  NULL
40748725    10  1   7/18/2017 15:09 14440596    64  NULL
40748723    10  1   7/18/2017 15:09 14440594    64  NULL
67383070    1   3   7/26/2018 14:15 14440594    26  13023588
67383078    7   4   7/26/2018 14:16 14440594    26  13023590
67383074    3   7   7/26/2018 14:15 14440594    26  13023589
40748726    10  1   7/18/2017 15:09 14440597    64  NULL
40748727    10  1   7/18/2017 15:09 14440598    64  NULL
40748728    10  1   7/18/2017 15:09 14440599    64  NULL
40748729    10  1   7/18/2017 15:09 14440600    64  NULL
71206458    10  1   8/27/2018 11:46 23900484    26  NULL
71206459    10  1   8/27/2018 11:46 23900485    26  NULL
112852911   10  1   5/24/2019 5:07  800002498   99  NULL
112852912   10  1   5/24/2019 5:07  800002499   99  NULL
112852913   10  1   5/24/2019 5:07  800002500   99  NULL
112852914   10  1   5/24/2019 5:07  800003019   99  NULL
92704214    3   2   3/22/2019 9:39  14440593    80  16533839
92704217    3   2   3/22/2019 9:39  14440595    80  16533842
92704218    3   2   3/22/2019 9:39  14440596    80  16533843
92704219    3   2   3/22/2019 9:39  14440597    80  16533844
92704215    3   2   3/22/2019 9:39  14440598    80  16533840
92704216    3   2   3/22/2019 9:39  14440599    80  16533841
92704220    3   2   3/22/2019 9:39  14440600    80  16533845
93598047    3   2   3/24/2019 9:51  23900484    80  16548757
77165368    3   2   10/22/2018 14:28    23900485    64  14221198
93598048    3   2   3/24/2019 9:51  23900485    80  16548758
92654993    1   3   3/21/2019 1:00  14440593    1   16531378
92654994    1   3   3/21/2019 1:00  14440595    1   16531379
121160006   2   3   6/20/2019 1:00  14440595    1   17411641
92654995    1   3   3/21/2019 1:00  14440596    1   16531380
121160007   2   3   6/20/2019 1:00  14440596    1   17411642
92654996    1   3   3/21/2019 1:00  14440597    1   16531381
92654997    1   3   3/21/2019 1:00  14440598    1   16531382
92654998    1   3   3/21/2019 1:00  14440599    1   16531383
102075451   2   3   4/24/2019 8:53  14440599    99  16875917
92654999    1   3   3/21/2019 1:00  14440600    1   16531384
92655000    1   3   3/21/2019 1:00  23900484    1   16531385
102075453   2   3   4/24/2019 8:55  23900484    99  16875919
75968834    1   3   10/13/2018 1:00 23900485    1   14157115
92655001    2   3   3/21/2019 1:00  23900485    1   16531386
122784894   3   4   6/26/2019 7:40  14440595    99  17548826
122784893   3   4   6/26/2019 7:40  14440596    99  17548825
112836464   7   4   5/23/2019 23:51 14440599    80  17238673
112836465   7   4   5/23/2019 23:52 23900484    80  17238674
102075452   3   7   4/24/2019 8:54  14440599    99  16875918
102075455   3   7   4/24/2019 8:56  23900484    99  16875921
Engagement example
engagement_id                            application_id start_date  end_date
APT_ItemProcessingOutsourcing_DLM_2018_07   735         7/16/2018   7/26/2018
Issues example
id  created issue_type  status_id   application_id   engagement_id
14440592    2017-07-18 15:09:09 EAPT    4   735     APT_ItemProcessingOutsourcing_DLM_2017_03
14440593    2017-07-18 15:09:09 EAPT    2   735     APT_ItemProcessingOutsourcing_DLM_2017_03
14440594    2017-07-18 15:09:10 EAPT    4   735     APT_ItemProcessingOutsourcing_DLM_2017_03
14440595    2017-07-18 15:09:10 EAPT    4   735     APT_ItemProcessingOutsourcing_DLM_2017_03
14440596    2017-07-18 15:09:10 EAPT    4   735     APT_ItemProcessingOutsourcing_DLM_2017_03
14440597    2017-07-18 15:09:10 EAPT    2   735     APT_ItemProcessingOutsourcing_DLM_2017_03
14440598    2017-07-18 15:09:10 EAPT    2   735     APT_ItemProcessingOutsourcing_DLM_2017_03
14440599    2017-07-18 15:09:10 EAPT    4   735     APT_ItemProcessingOutsourcing_DLM_2017_03
14440600    2017-07-18 15:09:10 EAPT    2   735     APT_ItemProcessingOutsourcing_DLM_2017_03
23900484    2018-08-27 11:46:38 EAPT    4   735     APT_ItemProcessingOutsourcing_DLM_2018_07
23900485    2018-08-27 11:46:38 EAPT    2   735     APT_ItemProcessingOutsourcing_DLM_2018_07
800002498   2019-05-24 05:07:28 EAPT    1   735     APT_ItemProcessingOutsourcing_DLM_2019_04
800002499   2019-05-24 05:07:28 EAPT    1   735     APT_ItemProcessingOutsourcing_DLM_2019_04
800002500   2019-05-24 05:07:28 EAPT    1   735     APT_ItemProcessingOutsourcing_DLM_2019_04
800003019   2019-05-24 05:07:28 EAPT    1   735     APT_ItemProcessingOutsourcing_DLM_2019_04


0 个答案:

没有答案