日期:2014-05-18  浏览次数:20572 次

SQL查询就改变一个连接方式,速度竟快了10多倍
SELECT   VXFTKeHuHuoPinYanSeGuiGeU.FH_KeHuBH,  
              CKeHu.KH_XingMing,
              VXFTKeHuHuoPinYanSeGuiGeU.FHMX_HuoPinBH,
              VXFTKeHuHuoPinYanSeGuiGeU.FHMX_YanSe,
              VXFTKeHuHuoPinYanSeGuiGeU.FHMX_GuiGe,
              ROUND(isnull(VXFSum.FShuLiang,0),0)   AS   FZongXiaoLiang   ,  
              ROUND(isnull(VXFSum.FJinE,0),2)   AS   FZongJinE   ,    
              ROUND(isnull(VXTSum.TShuLiang,0),0)   AS   XZongTuiLiang   ,  
              ROUND(isnull(VXTSum.TJinE,0),2)   AS   XZongJinE   ,
              ROUND(isnull(VXFSum.FShuLiang,0)   -   isnull(VXTSum.TShuLiang,0),0)   AS   ShiJiXiaoLiang   ,
              ROUND(isnull(VXFSum.FJinE,0)   -   isnull(VXTSum.TJinE,0),2)   AS   ShiJiXiaoShouJinE   ,
              ROUND((isnull(VXFSum.FShuLiang,0)   -   isnull(VXTSum.TShuLiang,0))/(isnull(a.F_ZSL,0)   -   isnull(b.T_ZSL,0)),4)   AS   ShiJiXiaoLiangBiLi   ,
              ROUND((isnull(VXFSum.FJinE,0)   -   isnull(VXTSum.TJinE,0))/(isnull(a.F_ZJE,0)   -   isnull(b.T_ZJE,0)),4)   AS   ShiJiXiaoShouJinEBiLi

    FROM   (   SELECT   DISTINCT   EXiaoShouFaHuo.FH_KeHuBH,  
                                EXiaoShouFaHuoMingXi.FHMX_HuoPinBH,
                                EXiaoShouFaHuoMingXi.FHMX_YanSe,
                                EXiaoShouFaHuoMingXi.FHMX_GuiGe
                      FROM   EXiaoShouFaHuo   INNER   JOIN
                                EXiaoShouFaHuoMingXi   ON  
                                EXiaoShouFaHuo.FH_FaHuoDanHao   =   EXiaoShouFaHuoMingXi.FHMX_FaHuoDanHao
                    WHERE   (EXiaoShouFaHuo.FH_Date   > =   ( '2000-1-1 '))   AND  
                                (EXiaoShouFaHuo.FH_Date   <=   ( '2008-1-1 '))
                UNION
                    SELECT   DISTINCT   EXiaoShouTuiHuo.TH_KeHuBH,  
                                  EXiaoShouTuiHuoMingXi.THMX_HuoPinBH,
                                  EXiaoShouTui