我这样做是为了根据地址和邮政编码字段中的数字查找与我们的员工具有匹配地址的供应商,但这确实很慢。该查询删除任何文本并将员工表中的数字连接到供应商表。
有什么方法可以提高查询性能?
SELECT
T1.EMPLID, T1.NAME, T1.ADDRESS1, T1.ADDRESS2, T1.ADDRESS3, T1.ADDRESS4, T1.CITY,
T2.VENDOR_ID, T3.NAME1, T2.ADDRESS1, T2.ADDRESS2, T2.ADDRESS3, T2.ADDRESS4, T2.CITY
FROM PS_PERSONAL_DATA T1
JOIN PS_VENDOR_ADDR T2
ON
TRANSLATE(T1.ADDRESS1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS2, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
SUBSTR(T2.POSTAL,0,5) =
TRANSLATE(T2.ADDRESS1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T2.ADDRESS2, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
SUBSTR(T2.POSTAL,0,5)
JOIN PS_VENDOR T3
ON T2.VENDOR_ID = T3.VENDOR_ID
WHERE T1.EMPLID <> T2.VENDOR_ID
AND
TRANSLATE(T1.ADDRESS1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS2, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
SUBSTR(T2.POSTAL,0,5) NOT LIKE ' '
AND T2.VENDOR_ID IN
(
SELECT VENDOR_ID
FROM PS_VOUCHER
WHERE PROCESS_INSTANCE <> 0
AND POST_STATUS_AP LIKE 'P'
AND VENDOR_ID NOT IN
(
'0000003730',
'0000003318',
'0000003555',
'0000002422',
'0000003458',
'0000001089',
'0000001450',
'0000003809',
'0000003255',
'0000001903'
)
HAVING SUM(GROSS_AMT) > 5000 AND COUNT(VENDOR_ID) > 2
GROUP BY VENDOR_ID
)
;