我有以下查询从notes
表中选择输入(例如:bob)不在orders
表中的所有内容。
SELECT * FROM `notes` WHERE notes.customer_email NOT IN
(SELECT customers_email_address FROM orders)
AND ((customer_phone LIKE '%bob%')
OR (customer_name LIKE '%bob%')
OR (customer_email LIKE '%bob%'))
AND customers_id IS NULL
GROUP BY `customer_email`
ORDER BY `customer_name`
DESC LIMIT 50
这个查询的胖男孩在我的开发机器上花费了大约 80 秒,在实时服务器上花费了大约 7 秒。
两个问题:
- 我对这个查询做错了什么?(我需要从错误中吸取教训)
- 如何改进此查询?