| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 478 人关注过本帖
标题:sql查询优化求助
只看楼主 加入收藏
yetianshi
Rank: 1
来 自:GZ
等 级:新手上路
帖 子:14
专家分:0
注 册:2012-7-26
结帖率:100%
收藏
 问题点数:0 回复次数:0 
sql查询优化求助
select a.*,b.ServiceNum,f. bjl,c.BatchNum,e.BatchGreaterThan30 , d.LessThan5s
  from  
              (--获取部门名称
               select Cwno,DeptName
               from GkjlL_His_His a
               inner join
               OPENDATASOURCE('SQLOLEDB','Data Source=172.17.240.93;User ID=sa;Password=!QAZ2wsx').pddbgz.dbo.[YwCk] e
               on  a.Cwno = e.Wno
               GROUP BY DeptName,a.Cwno) a
               
 inner join ( --计算窗口服务人次
        select Cwno, count(0) ServiceNum
          from GkjlL_His_His
         where Cdate >= '2012-04-01'
           and Cstate = '处理完毕'
           and Btime != ''
         group by Cwno) b on a.Cwno = b.Cwno
         


 inner join (
             --计算批量次数
             select Cwno, count(0) BatchNum
               from GkjlL_His_His
              where Cdate >= '2012-04-01'
                and Cstate = '处理完毕'
                and Btime != ''
                and BatchCnt != 0
              group by Cwno) c on a.Cwno = c.Cwno

 inner join (
             --计算小于5秒人数
             select Cwno, count(0) LessThan5s
               from GkjlL_His_His
              where Cdate >= '2012-04-01'
                and Cstate = '处理完毕'
                and Btime != ''
                and DATEDIFF(S, Btime, Etime) < 5
              group by Cwno) d on a.Cwno = d.Cwno
              
  inner join
              (--计算批量号>30次数
              select Cwno,count(0) BatchGreaterThan30
              from  GkjlL_His_His
              where Cdate >= '2010-04-01'
              and Cstate='处理完毕'
              and Btime!=''
              and BatchCnt>'30'  
              group by Cwno) e on a.Cwno = e.Cwno
              
   inner join
              (--计算办件量
              select a.Cwno ,sum(BatchCnt)+count(0)-b.BatchNum bjl   
              from  GkjlL_His_His a
              inner join
              (--计算批量次数
             select Cwno, count(0) BatchNum
               from GkjlL_His_His
              where Cdate >= '2012-04-01'
                and Cstate = '处理完毕'
                and Btime != ''
                and BatchCnt != 0
              group by Cwno) b on a.Cwno = b.Cwno
              where Cdate >= '2010-04-01'
              and Cstate='处理完毕'
              and Btime!=''
              group by a.Cwno,b.BatchNum )
              f on a.Cwno = f.Cwno
              
每个join 都重复查询了一部分数据,哪位大神可以帮忙给个优化方案?先谢过啦
搜索更多相关主题的帖子: 查询 优化 inner count 
2012-07-30 11:34
快速回复:sql查询优化求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030684 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved