我有一個查詢需要花費很長時間才能在Oracle中完成。它在我殺死它之前跑了幾個小時。有什麼方法可以加快速度嗎?我的查詢需要很長時間才能完成
這裏是我的查詢:
select distinct(random_selection.randnum),
random_selection.dropper_id,
random_selection.ozip3
from random_selection
where random_selection.dropper_id is not null
and random_selection.quarter = 121
and (random_selection.dropper_id, random_selection.randnum, random_selection.quarter) in
(select forecast_entry.dropper, forecast_entry.rand_num, production_weeks.yyq
from forecast_entry, production_weeks
where forecast_entry.week = production_weeks.production_week
and production_weeks.project_cd = 'EXFC'
and production_weeks.yyq >= 121)
union
select distinct(random_selection.randnum),
dropper_city_brk_2.dropper_id,
random_selection.ozip3
from random_selection, dropper_city_brk_2, dropper
where random_selection.ozip3 = dropper_city_brk_2.zip3
and dropper.dropper_id = dropper_city_brk_2.dropper_id
and dropper.active = 1
and dropper_city_brk_2.dropper_id <> 10002
and random_selection.quarter = 121
and random_selection.dropper_id is null
and (random_selection.dropper_id, random_selection.randnum, random_selection.quarter) in
(select forecast_entry.dropper, forecast_entry.rand_num, production_weeks.yyq
from forecast_entry, production_weeks
where forecast_entry.week = production_weeks.production_week
and production_weeks.project_cd = 'EXFC'
and production_weeks.yyq >= 121)
查詢解釋說:
主要目的是讓所有的randnum,dropper_id,並ozip3從random_selection表不在forecast_entry表,並在yyq 121中有一個項目代碼EXFC。通過關聯周和生產周,可以從production_weeks表中檢索yyq。一些dropper_id爲null,因此我們需要通過關聯ozip3和zip3從dropper_city_brk_2表中提取數據。我們不希望dropper_id處於非活動狀態,因此它們必須有活動的等於1,這是通過關聯dropper表。
希望這有助於
您應該在問題中包含您的表格模式以及您設置的任何索引。 – jadarnel27
這是我在生活中見過的最大的SQL查詢:)讀取它必須要稍作休息 –
我已經看到更大的...... –