我试图优化此查询,但可能。在我的测试表中,这也完全符合我的要求,但在实时表上,这需要很长时间才能运行。Oracle/SQL - 需要帮助优化此联合/组/计数查询
select THING_,
count(case STATUS_ when '_Good_' then 1 end) as GOOD,
count(case STATUS_ when '_Bad_' then 1 end) as BAD,
count(case STATUS_ when '_Bad_' then 1 end)/count(case STATUS_ when '_Good_' then 1 end) * 100 as FAIL_PERCENT
from
(
select THING_,
STATUS_,
from <good table>
where TIMESTAMP_ > (sysdate - 1) and
STATUS_ = '_Good_' and
upper(THING_) like '%TEST%'
UNION ALL
select THING_,
STATUS_,
from <bad table>
where TIMESTAMP_ > (sysdate - 1) and
STATUS_ = '_Bad_' and
THING_THING_ like '%TEST%'
) u
group by THING_
我想通过查看查询它应该是自我解释什么,我想做的事,但如果没有,或者如果需要额外的信息,请让我知道,我会张贴一些示例表。
谢谢!
是'好桌子'和'坏桌子'真正的桌子,而不是e。 G。视图,嵌套查询等? – Quassnoi 2011-01-26 15:52:35