从多个表中检索花费的时间太长

时间:2013-07-31 06:41:58

标签: php sql

您好我正在从多个表中检索并显示结果,但这花费的时间太长了。

以下是我的数据库代码:

"SELECT count(distinct KGBupdate.gsxNo) as sat FROM KGBupdate 
    RIGHT JOIN ContactCenter ON KGBupdate.ackNo=ContactCenter.ackNo
    LEFT JOIN CustomerFeed ON ContactCenter.callId = CustomerFeed.callId
    WHERE date(ContactCenter.callClose) BETWEEN '".$start."' AND '".$end."'
    AND KGBupdate.gsxNo!=''
    AND ContactCenter.callStatus = 'Close'
    AND CustomerFeed.overall IN ( 1, 2 ) 
    AND ContactCenter.location='".$location[$i]."' "

加快使用索引

的方法是什么?

提前致谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT count(distinct KGBupdate.gsxNo) as sat FROM KGBupdate 
    RIGHT JOIN ContactCenter ON KGBupdate.ackNo=ContactCenter.ackNo and ContactCenter.callStatus = 'Close' and ContactCenter.location='".$location[$i]."' "
    LEFT JOIN CustomerFeed ON ContactCenter.callId = CustomerFeed.callId and CustomerFeed.overall IN ( 1, 2 ) 
    WHERE date(ContactCenter.callClose) BETWEEN '".$start."' AND '".$end."'
    AND KGBupdate.gsxNo!=''