sql 语句优化?寻求帮助,谢谢

 SELECT yinshua.orderid, chengpin.ChanChenPengName,chengpin.id, lingliao.zhongliang                           
        AS lingliaozhong, yinshua.ycluse, tui.zhong AS tuiliaozhong,                     
        chengpin.ChanChenPengGuiGe, ordertable.number, yinshua.feimo, yinshua.zhengmo,                   
        yinshua.huansu, yinshua.seshu, yinshua.huankunshu, yinshua.zhengmozhong,                         
        yinshua.fenqie + yinshua.yuanmo + yinshua.chuimo + yinshua.qita + yinshua.feipin + yinshua.zonghe
         + yinshua.zhengmozhong AS feipinzhong, yinshua.producehour,                                     
        yinshua.zhuangbanhour, yinshua.tiaosehour, yinshua.zhuanhuanhour,                                
        yinshua.waithour, yinshua.qualityhour, yinshua.repairhour, yinshua.otherhour,                    
        yinshua.banzu, yinshua.producedate, yinshuachanpinku.zhong                      
        AS zhong, yinshuachanpinku.chang AS chang,yinshuachanpinku.mianji AS mianji,                                               
        yinshua.feipin + yinshua.zonghe AS banchengpinfeipin,                                            
        yinshua.fenqie + yinshua.yuanmo + yinshua.chuimo + yinshua.qita AS yuanliaofeipin,               
        yinshua.banci, yinshua.jitai, yinshua.cid1, yinshua.cid2, yinshua.cid3, yinshua.cid4,            
        yinshua.fenqie, yinshua.yuanmo, yinshua.chuimo, yinshua.qita, yinshua.feipin,                    
        yinshua.zonghe, yinshua.maintainhour, yinshua.noorderhour, yinshua.noElehour,                    
        yinshua.beginEle, yinshua.endEle, yinshua.userid, yinshua.userid1                                
  FROM yinshua INNER JOIN  ordertable ON yinshua.orderid = ordertable.Orderid INNER JOIN                                    

            (SELECT ChanChenPengId AS id, ChanChenPengName, ChanChenPengGuiGe                            
           FROM ChanChenPeng                                                                             
           UNION                                                                                         
           SELECT yuancailiaoId AS id, yuancailiaoName AS ChanChenPengName,                              
                 cast(yuancailiaohoudu AS varchar(50))                                                   
                 + '*' + cast(yuancailiaokuandu AS varchar(50)) AS ChanChenPengGuiGe                   
           FROM yuancailiaoInf) chengpin ON                                                              
        ordertable.chanchenpengid = chengpin.id


LEFT OUTER JOIN 
            (SELECT producedate,banzu,  orderid, SUM(zhong) AS zhong, SUM(chang)                         
                 AS chang, SUM(mianji) AS mianji                                                         
           FROM yinshuachanpinku                                                                         
           GROUP BY producedate,banzu,  orderid)                                                         
        yinshuachanpinku ON                        
        yinshua.orderid = yinshuachanpinku.orderid AND                                                   
        yinshua.banzu = yinshuachanpinku.banzu and yinshua.producedate=yinshuachanpinku.producedate

 

LEFT OUTER JOIN 
            (SELECT orderid, banzu,  gongxu,  SUM(zhongliang) AS zhong                                   
           FROM lingliao                                                                                 
           WHERE (state LIKE 't%') AND (ycltmh is not NULL) AND (gongxu = 'ys')                            
           GROUP BY orderid, banzu, gongxu) tui ON                                                       
        yinshua.orderid = tui.orderid COLLATE Chinese_PRC_CI_AS AND                                      
        yinshua.banzu = tui.banzu COLLATE Chinese_PRC_CI_AS

 

LEFT OUTER JOIN                              
            (SELECT SUM(zhongliang) AS zhongliang, orderid, banzu                                        
           FROM lingliao                                                                                 
           WHERE (gongxu = 'ys') AND (state = 'y') OR                                                
                 (state = 'l')                                                                         
           GROUP BY orderid, banzu) lingliao ON                                                          
        yinshua.banzu = lingliao.banzu COLLATE Chinese_PRC_CI_AS AND                                     
        yinshua.orderid = lingliao.orderid COLLATE Chinese_PRC_CI_AS   

where (yinshua.producedate = '2009-10-12')

你可能感兴趣的:(sql 语句优化?寻求帮助,谢谢)