I ve got a slow performing query. I know using a dependent subquery is bad, but I can t think of another way to get the data I want.
基本上,我要向过去6个月至少有50张发票但本月没有发票的客户表示。
这就是我目前的情况:
select
Customer.name,
Customer.id,
Customer.latitude,
Customer.longitude
from
Customer
where
EXISTS (
SELECT
*
FROM
Invoice_Header
WHERE
Invoice_Header.inv_date BETWEEN 2011-03-02 AND 2011-10-02
AND
Invoice_Header.account_number = Customer.account_number
HAVING COUNT(invoice_num) > 50
)
AND NOT EXISTS (
SELECT *
FROM
Invoice_Header
WHERE
InvHead.inv_date > 2011-10-02
AND
InvHead.account_number = Customer.account_number
)
Group by name;
客户表有大约12k记录,Invoice_Header有大约2米记录。
我的指数为:日数,账户编号(两个表)。
希望能就如何加快这项工作提出建议。