我正在尝试将查询从 NOT IS 子句转换为左外连接以获得更好的性能。
以下是我的完美查询
SELECT a.company_code, account_name, legal_name FROM accounts a
WHERE account_id NOT IN (SELECT DISTINCT account_id FROM phone_calls WHERE status = 2 ) AND account_id >10000
ORDER BY legal_name, account_name, account_id
因此,我想将其更改为左连接或某种类型的连接,以执行相同的查询。我已经尝试过了,但它对我不起作用
SELECT a.company_code, a.account_name, a.legal_name, p.phone_call_id
FROM accounts AS a
LEFT JOIN phone_calls AS p ON p.account_id = a.account_id
WHERE a.account_id >= 10000 AND p.status = 2 AND p.phone_call_id IS NULL
ORDER BY a.legal_name, a.account_name, a.account_id
我的第二个查询总是什么都不返回。
我已经尝试过这个查询,这给了我比第一个查询更多的结果,所以它不一样
SELECT a.company_code, a.account_name, a.legal_name, p.phone_call_id
FROM accounts AS a
LEFT JOIN phone_calls AS p ON p.account_id = a.account_id AND p.status = 2 AND a.account_id >= 10000
WHERE p.account_id IS NULL
ORDER BY a.legal_name, a.account_name, a.account_id