2014-03-19 169 views
0

我有以下查詢,只有800記錄服用5個minits運行,可你一些幫助,請MySQL查詢速度很慢時,將子查詢

SELECT 

vtiger_salesorder.salesorderid,vtiger_salesorder.salesorder_no,vtiger_salesorder.sostatus, 
(SELECT se.s_date 
FROM 
softMax_events as se 
INNER JOIN vtiger_salesorder as bm ON bm.salesorderid = se.orderNum 
where (bm.sostatus = 'Order' AND se.orderNum = vtiger_salesorder.salesorderid) AND se.appointTyp='60' 
group by bm.salesorderid Limit 0,1) As sdate 

FROM 
    vtiger_salesorder 
Inner Join vtiger_crmentity ON vtiger_salesorder.salesorderid = vtiger_crmentity.crmid 
WHERE (vtiger_salesorder.sostatus = 'Order') 
and (vtiger_crmentity.deleted<>'1') 

回答

0

嘗試此查詢,希望是這樣,這將幫助你,

SELECT vtiger_salesorder.salesorderid,vtiger_salesorder.salesorder_no,vtiger_salesorder.sostatus,se.s_date 
    FROM vtiger_salesorder 
    Inner Join vtiger_crmentity ON vtiger_salesorder.salesorderid = vtiger_crmentity.crmid 
    INNER JOIN softMax_events se ON se.orderNum = salesorderid 
    WHERE (vtiger_salesorder.sostatus = 'Order') AND/OR 
    se.orderNum = vtiger_salesorder.salesorderid AND se.appointTyp='60' 
    and (vtiger_crmentity.deleted<>'1') 

編輯: 我注意到,有vtiger_salesorder and softMax_events之間的一些關係,你可以使用這兩個表的連接,並以這種方式,你可以刪除內部查詢,我想它可能會對其進行測試。這將有助於你確定一些修改後。

+0

您好zzzz,我很好... thansk – user3428559

+0

@ user3428559,如果有幫助,您可以接受答案。 – NAZIK