SELECT DISTINCT 
                S.so_no, S.sales, S.ignore, S.cartage, S.payment1, S.financial, S.customer_name, W.Result, S.trans_free, S.trans_fee, 
                S.so_date, S.curr, S.tax, S.customer_code, S.TOTALAMOUNT
FROM      Customer_Master AS C INNER JOIN
                Pi_Master AS P ON C.customer_code = P.customer_code INNER JOIN
                So_Master AS S ON C.customer_code = S.customer_code INNER JOIN
                wf_status AS W ON S.so_no = W.doc_no INNER JOIN
                order_detail_total AS O ON S.so_no = O.doc_no
WHERE   (S.so_date BETWEEN '2010/1/1 00:00:00' AND '2011/1/1 23:59:00')高人指点下,如何优化上边的语句,现在只有跑二个月的很慢,想优化一下,谢谢

解决方案 »

  1.   

    Pi_Master,order_detail_total连这两张表做什么
      

  2.   

    语句看不出问题,因为不知道你的业务逻辑,给联接的字段加上索引,给where里的字段加上索引,
      

  3.   


    SELECT DISTINCT S.so_no, S.sales, S.ignore, S.cartage, S.payment1, S.financial, S.customer_name, 
                  W.Result, S.trans_free, S.trans_fee, 
      S.so_date, S.curr, S.tax, S.customer_code, S.TOTALAMOUNTFROM Customer_Master AS C 
    INNER JOIN Pi_Master AS P ON C.customer_code = P.customer_code 
    INNER JOIN So_Master AS S ON C.customer_code = S.customer_code 
    INNER JOIN wf_status AS W ON S.so_no = W.doc_no 
    INNER JOIN order_detail_total AS O ON S.so_no = O.doc_no
    WHERE (S.so_date BETWEEN '2010/1/1 00:00:00' AND '2011/1/1 23:59:00')看你的查询,字段和条件里只用到了 S W 两个表的字段,为毛要关联C P O三个表?
      

  4.   


    SELECT DISTINCT  
      s.so_no, s.sales, s.ignore, s.cartage, s.payment1, s.financial, s.customer_name, w.result, s.trans_free, s.trans_fee,  
      s.so_date, s.curr, s.tax, s.customer_code, s.TOTALAMOUNT
    FROM so_master AS s INNER JOIN wf_status AS w
        ON s.so_no = w.doc_no
    WHERE (s.so_date BETWEEN '2010/1/1 00:00:00' AND '2011/1/1 23:59:00')