如何查询这些复杂的数据?它不仅仅是关于连接,我还需要了解查询将如何工作

5ssjco0h  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(162)

我有两张table,虫子和虫子历史。以下数据分别对应于它们的模式:
漏洞:


**BugId Priority Severity PlatformFound GameArea TestType**

-----------------------------------------------------------

23  0 - QA - Before Beta        Common      Ad Hoc Testing
46  0 - QA - Before Beta        Common      Ad Hoc Testing
69  0 - QA - Before Beta    C   Common  Art Ad Hoc Testing
92  0 - QA - Before Beta    B   Common  Audio   Ad Hoc Testing
138 1 - Dev - Medium        Playstation 4       Ad Hoc Testing
184 0 - QA - Before Beta    A   Common  Game Modes  Ad Hoc Testing
207 0 - QA - Before Beta    C   Common  Art Ad Hoc Testing
230 0 - QA - Before Beta    C   Common  Art Ad Hoc Testing
253 0 - QA - Before Beta        Common      Ad Hoc Testing
276 0 - QA - Before Beta    C   Common  Art Ad Hoc Testing
299 0 - QA - Before Beta    C   Playstation 4   Game Modes  Ad Hoc Testing
322 0 - QA - Before Beta    C   Common  Game Modes  Ad Hoc Testing
345 0 - QA - Before Beta    NULL    Common  NULL    Ad Hoc Testing
368 0 - QA - Before Beta    C   Common  Art Ad Hoc Testing
391 0 - QA - Before Beta        Common      Free Testing
414 0 - QA - Before Beta    C   Common  Game Modes  Free Testing
437 0 - QA - Before Beta    C   Common  Art Ad Hoc Testing
460 0 - QA - Before Beta    C   Common  Game Modes  Ad Hoc Testing
483 0 - QA - Before Beta    C   Common  Art Ad Hoc Testing

错误历史:

BugId   FullDate      ProgressStatus
23     2016-11-29   Submitted
23     2016-11-30   Submitted
23     2016-12-01   Submitted
23     2016-12-02   Submitted
23     2016-12-03   Submitted
23     2016-12-04   Submitted
46     2017-07-17   Closed - Fixed
46     2017-07-18   Closed - Fixed
46     2017-07-19   Closed - Fixed
46     2017-07-20   Closed - Fixed
46     2017-07-21   Closed - Fixed
46     2017-07-22   Closed - Fixed
46     2017-07-23   Closed - Fixed
69     2016-11-29   Submitted
69     2016-11-30   Submitted
69     2016-12-01   Submitted
69     2016-12-02   Submitted

我需要创建一个sql查询来合并来自“bughistory”和“bugs”的数据,这样我就可以得到每个“fulldate”的严重性-a bug的计数。结果中只包含计数超过7个错误的天数。
我的问题是:

SELECT count(bugs.BugID), bughistory.fullDate severity_A FROM 'Bugs' bugs
INNER JOIN 'BugHistory' bughistory ON bugs.BugID = bughistory.BugId where bugs.Severity = 'A' 
GROUP BY(bughistory.FullDate) Having count(bugs.BugID) > 7;
fcg9iug3

fcg9iug31#

我们可以 INNER JOIN 在两张table之间使用 BugId 以及 Severity = 'A' . 那我们就可以了 GROUP BYFullDate 以及 Count(Distinct ..) 可用于计算特定日期的唯一错误。
最终, HAVING 子句将只考虑那些错误大于或等于7的日期。

SELECT 
  bh.FullDate, 
  COUNT(DISTINCT bh.BugId) AS total_bugs 
FROM BugHistory AS bh 
JOIN Bugs AS b 
  ON b.BugId = bh.BugId AND 
     b.Severity = 'A'
GROUP BY bh.FullDate 
HAVING total_bugs >= 7

相关问题