我可以在mysql中获得多个条件的错误总数吗?
我的要求是,我需要获得具有某些优先级的 bugid 的总和或计数,比如 P1,它超过了特定时间,但是超出的计数应该从该特定优先级的总计数中计算出来。
我的查询是:-
select
sum(
IF(priority="P1",1,0)) P1,
sum(
IF(timediff(delta_ts,creation_ts) > "00:00:05",1,0))P1_exeeded,
SUM(
IF(priority="P2",1,0)) P2,
sum(
IF(timediff(delta_ts,creation_ts) > "00:00:10",1,0))P2_exeeded,
SUM(
IF(priority="P3",1,0)) P3count,
SUM(
IF(priority="P4",1,0)) P4count,
SUM(
IF(priority="P5",1,0)) P5count,
SUM(
IF(priority="P6",1,0)) P6count,
SUM(
IF(priority="P7",1,0)) P7count,
SUM(
IF(priority="P8",1,0)) P8count
from bugs
where bugs.product_id=237
and bugs.resolution='FIXED'
and bugs.creation_ts >='2013-06-14 09:00:00'
and bugs.creation_ts <= '2013-06-16 08:59:59'
and bug_status="RESOLVED";
我得到的结果是: -
------+------------+------+------------+---------+ ---------+---------+---------+---------+---------+ | P1 | P1_exeeded | P2 | P2_exeeded | P3count | P4count | P5count | P6count | P7count | P8count | +--------+------------+------+------------+--------- +---------+---------+---------+---------+--------- + | 7 | 19 | 6 | 18 | 5 | 1 | 0 | 0 | 0 | 0 | +--------+------------+------+------------+--------- +---------+---------+---------+---------+--------- + 一组中的 1 行(0.00 秒)
但是我需要通过以下两个条件来计算每个优先级中超出的错误 ID 的总和:-
超过特定时间限制的超出 bugid 的总和,其取自其特定优先级类别的计数。
在每种情况下,超出的错误 ID 总和应满足这两个条件。
我拥有的 P1 优先级错误 ID 总数。P1_exeeded = IF(timediff(delta_ts,creation_ts) > "00:00:05",1,0)) 取自 P1 bugid 的计数。
请帮助在mysql中使用sum(满足2个条件)