简体   繁体   English

MySql 计数失败代码的出现次数

[英]MySql count occurrences of failure codes

I am trying to count the number of times something happened with a failure status in my database and retrieve the name of the failure.我正在尝试计算数据库中发生故障状态的次数并检索故障名称。 I have a table builds that holds what the failurearea is and table called failureareas that has the names of all the failurearea codes.我有一个表builds ,其中包含failurearea区域和称为failureareas的表,其中包含所有故障区域代码的名称。 I want to be able to count these so I can graph out the data and tell our devs how their builds most commonly fail.我希望能够对这些进行计数,以便绘制数据并告诉我们的开发人员他们的构建最常失败的原因。

This is what I am trying, but it isn't working:这是我正在尝试的,但它不起作用:

SELECT COUNT(B.id), F.name 
   FROM builds B 
  JOIN failureareas F ON B.failurearea = F.id
 WHERE DATE(B.submittime) >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) 
   AND B.buildstatus != 2

You need to use GROUP BY:您需要使用 GROUP BY:

SELECT COUNT(B.id), F.name
FROM builds B  JOIN failureareas F ON B.failurearea = F.id
WHERE DATE(B.submittime) >=  DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND B.buildstatus != 2
GROUP BY F.name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM