2017-01-24 16 views
1
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分後に15000レコードが返されます。このレコードは問題ではありません。
一部のチュートリアルでは、内部結合、左結合、... を使用することをお勧めしますが、Join句でこのクエリを変換する方法がわかりません。 助けていただければ幸いです。前もって感謝します。内部結合を使用してmysqlクエリを最適化する方法

答えて

関連する問題