我可以用其他任何形式重新排列以下查询吗?
SELECT
ELIG_TYP
FROM TABLE1
WHERE COMPANY_CD IN
(SELECT SUBSTR(CMPNYID, 1, 4) FROM TABLE2 WHERE USR = 'Badshah')
答案 0 :(得分:0)
您可以使用join:
SELECT ELIG_TYP
FROM TABLE1
INNER JOIN TABLE2 ON TABLE1.COMPANY_CD = LEFT(TABLE2.CMPNYID, 4)
AND USR = 'Badshah'
答案 1 :(得分:0)
尝试使用存在:
SELECT f1.ELIG_TYP
FROM TABLE1 f1
WHERE exists
(
SELECT * FROM TABLE2 f2
WHERE f2.USR = 'Badshah' and substr(f2.CMPNYID, 1, 4)=f1.COMPANY_CD
)
或者如果你仍有性能问题,请尝试:
SELECT f1.ELIG_TYP
FROM TABLE1 f1
WHERE exists
(
SELECT * FROM TABLE2 f2
WHERE f2.USR = 'Badshah' and f2.CMPNYID like f1.COMPANY_CD || '%'
)