繁体   English   中英

如何使用内连接优化mysql查询

[英]how to optimize mysql query with inner join

select id from customer_details where store_client_id = 2 
And
    id  NOT IN (select customer_detail_id from  orders 
        where store_client_id = 2 and total_spent > 100 GROUP BY customer_detail_id ) 
Or
    id IN (select tcd.id from property_details as pd, customer_details as tcd 
        where pd.store_client_id = 2 and pd.customer_detail_id = tcd.customer_id and pd.property_key = 'Accepts Marketing' 
        and pd.property_value = 'no') 
And 
    id IN (select customer_detail_id from orders 
        where store_client_id = 2 GROUP BY customer_detail_id HAVING count(customer_detail_id) > 0 ) 
Or
    id IN (select tor.customer_detail_id from ordered_products as top, orders as tor 
        where tor.id = top.order_id and tor.store_client_id = 2 
        GROUP BY tor.customer_detail_id having sum(top.price) = 1)`

我有这个带有内部连接的 mysql 查询,所以当它在 mysql 服务器中运行时,它会减慢无法找到的问题。
但 4-5 分钟后,它返回 15 000 条记录。 这个记录可能不是问题。
在一些教程中建议使用内连接,左连接,...但我不知道如何在 Join 子句中转换这个查询。 任何帮助将不胜感激。 提前致谢。

首先请阅读关系模型优化选择语句

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM