我有查询,它给出了正确的结果,但是,它有内部查询,重复相同的条件。我试图从我的结尾尽可能缩短查询的长度。
任何人都可以帮助我降低查询的复杂性,因为在服务器中获取结果需要 12 分钟,这可能会在未来引起很多问题。
问题是,重复相同的条件,并且查询在其中使用内部查询。
使用这些 mysql 参数查询:-
sum,if,GROUP_CONCAT在其中。
询问:-
select
sum(
IF(priority="P1",1,0)) P1,
sum(
IF((timediff(delta_ts,creation_ts) > "00:02:00")
&& (priority="P1") ,1,0))P1_exeeded,
(select
GROUP_CONCAT( DISTINCT bug_id)
from bugs
where
(
IF((timediff(delta_ts,creation_ts) > "00:02:00") && (priority="P1")
&& (product_id=237)
&&(bugs.resolution='FIXED')
&&(bug_status="RESOLVED")
&&(bugs.creation_ts >='2013-06-14 09:00:00'
&& bugs.creation_ts <= '2013-06-16 08:59:59') ,1,0)
)
) as bug_ids,
SUM(
IF(priority="P2",1,0)) P2,
sum(
IF((timediff(delta_ts,creation_ts) > "00:01:00")
&& (priority="P2") ,1,0))P2_exeeded,
(select GROUP_CONCAT( DISTINCT bug_id)
from bugs
where
(
IF((timediff(delta_ts,creation_ts) > "00:02:00")
&& (priority="P2")
&& (product_id=237)&&(bugs.resolution='FIXED')
&&(bug_status="RESOLVED")&&(bugs.creation_ts >='2013-06-14 09:00:00'
&& bugs.creation_ts <= '2013-06-16 08:59:59') ,1,0)
)
) as bug_ids,
SUM(
IF(priority="P3",1,0)) P3count,
SUM(
IF(priority="P4",1,0)) P4count
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 | bug_ids | P2 | P2_exeeded | bug_ids | P3count | P4count | +--------+------------+---------+------+------------ +---------+---------+---------+ | 7 | 1 | 3743304 | 6 | 1 | 3743305 | 5 | 1 | +--------+------------+---------+------+------------ +---------+---------+---------+
- 为了获取错误 ID,我使用了 group concat。查询变得复杂