我試圖優化此查詢,但可能。在我的測試表中,這也完全符合我的要求,但在實時表上,這需要很長時間才能運行。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