我正在查詢和使用oracle sql開發者真的很快提出了一個看法,幾乎幫助我做一些事情,我不知道該怎麼做。Oracle SQL Query在視圖上真的很慢但不是真正的表?
基本上我做了視圖,因爲我們的數據庫中的列不是必需的,在某些情況下,行是NULL或寫入不正確的註釋。這些行將包含「文本」列,其中會包含諸如「調整至銳步」帳戶等註釋。爲了正確運行我的查詢,我需要將每行都映射到'CUSTOMER_NO'值。
下面是這個視圖
SELECT t.*,
CASE
WHEN LENGTH(CUSTOMER_NO) != '6' and text like '%Nike%' or CUSTOMER_NO IS NULL and text like '%Nike%' THEN 'NIK001'
WHEN LENGTH(CUSTOMER_NO) != '6' and text like '%Nike%' or CUSTOMER_NO IS NULL and text like '%Reebok%' THEN 'REB001'
ELSE CUSTOMER_NO
END as CUSTOMER_NO_ADJUSTED
FROM
gen_led_voucher_row_tab t
所以這個觀點基本上都添加了一個新列「CUSTOMER_NO_ADJUSTED」,現在有一欄是100%填充。作品我預期的好。
但是,當我在這個視圖上運行我的原始查詢它只是繼續運行,並永遠不會結束/提取行。我讓它走了10分鐘,一無所獲。當我在表格上運行類似的查詢時,我會在30秒內得到數據。
下面是我試圖運行的查詢。我想基本上將CODE_D值分組爲一個部門名稱,並使用'EXISTS'選項運行查詢一次,以查看誰是現有客戶(在XXX個月內與我們做過業務),然後再以「NOT EXISTS」的形式運行它理論上只會產生新業務的部門價值(在指定月份內沒有與我們進行業務往來的客戶)。
SELECT
/* CASE statement to rename CODE_D product lines to what the product is. List was provided by accounting in June of 2014 */
CASE
WHEN CODE_D = '11' or CODE_D = '12' or CODE_D = '18' or CODE_D IS NULL THEN 'Laces'
WHEN CODE_D = '15' or CODE_D = '16' or CODE_D = '40' or CODE_D = '45' or CODE_D = '50'
or CODE_D = '55' or CODE_D = '60' or CODE_D = '65' or CODE_D = '67' or CODE_D = '30'
or CODE_D = '35' THEN 'Custom Soles'
WHEN CODE_D = '17' THEN 'Custom Heels'
WHEN CODE_D = '19' or CODE_D = '39' or CODE_D = '49' or CODE_D = '59' or CODE_D = '69'
THEN 'Socks'
WHEN CODE_D = '14' THEN 'Sneakers'
WHEN CODE_D = '89' THEN 'Dress Shoes'
WHEN CODE_D = '99' THEN 'Other'
ELSE 'UNKNOWN'
END as DEPARTMENT,
sum(coalesce(credit_amount, 0) - coalesce(debet_amount,0)) as TOTAL
FROM
KPIC_MIKE_METRIC1 a
where ACCOUNTING_YEAR like '2014'
and ACCOUNT not like '4010'
and ACCOUNT like '4%'
and Exists
(
Select *
From KPIC_MIKE_METRIC1 b
where voucher_date >= '01-FEB-13'
and voucher_date < '01-FEB-14'
and ACCOUNT not like '4010'
and ACCOUNT like '4%'
and (credit_amount > '1' or debet_amount > '1')
and a.CUSTOMER_NO_ADJUSTED = b.CUSTOMER_NO_ADJUSTED
)
GROUP BY
/*
This GROUP BY statement needs to contain an entire copy of the CASE statement, minus the alias.
If changes are made to the CASE statement please update this GROUP BY statement
*/
CASE
WHEN CODE_D = '11' or CODE_D = '12' or CODE_D = '18' or CODE_D IS NULL THEN 'Laces'
WHEN CODE_D = '15' or CODE_D = '16' or CODE_D = '40' or CODE_D = '45' or CODE_D = '50'
or CODE_D = '55' or CODE_D = '60' or CODE_D = '65' or CODE_D = '67' or CODE_D = '30'
or CODE_D = '35' THEN 'Custom Soles'
WHEN CODE_D = '17' THEN 'Custom Heels'
WHEN CODE_D = '19' or CODE_D = '39' or CODE_D = '49' or CODE_D = '59' or CODE_D = '69'
THEN 'Socks'
WHEN CODE_D = '14' THEN 'Sneakers'
WHEN CODE_D = '89' THEN 'Dress Shoes'
WHEN CODE_D = '99' THEN 'Other'
ELSE 'UNKNOWN'
END
ORDER BY TOTAL DESC
任何幫助,將不勝感激。我是一個新手,我相信我可能會得到一些更好的建議,如何在這裏正確運行。任何幫助表示讚賞!
什麼是執行計劃說什麼? –