SQL1:
select sLY,sum(fZJE) from (
select sLY,sum(fZJE) as fZJE from DB1..MXB where dSJ>'2009-10-1' and dSJ<'2010-4-30' group by sLY
union all
select sLY,sum(fZJE) as fZJE from DB2..MXB where dSJ>'2009-10-1' and dSJ<'2010-4-30' group by sLY)a
group by sLYSQL2:
select sLY,sum(fZJE) from (
select * from DB1..MXB where dSJ>'2009-10-1' and dSJ<'2010-4-30'
union all
select * from DB2..MXB where dSJ>'2009-10-1' and dSJ<'2010-4-30')a
group by sLYSQL3:
select sLY,sum(fZJE) from (
select * from DB1..MXB
union all
select * from DB2..MXB)a
where dSJ>'2009-10-1' and dSJ<'2010-4-30'
group by sLYMXB数据为200w~400w左右,请问,在SQL2000下,哪个SQL效率最高?

解决方案 »

  1.   

    1.把里面的dSJ>'2009-10-1' and dSJ<'2010-4-30'都换成between。。and
    2.分别旋转三条语句,ctrl + L 查看执行计划,看看有没有table scan的地方,有的话将
    相关字段加上index
      

  2.   

    dSJ是集聚索引,在查询分析器中查看查询成本,SQL1:33.34% SQL2:33.33% SQL3:33.33%
      

  3.   

    没有table scan就可以了,语句方面都差不多,你执行看看效能怎么样?
      

  4.   

    set statistics io on
    set statistics time on 
    执行的SQL语句
    set statistics time off 
    set statistics io off
      

  5.   

    select * from DB1..MXB where sXM>'2'
    sXM字段不是索引,我查看执行计划,也没table scan呀,显示Clustered Index Scan
      

  6.   

    index scan是可以的,没有问题。
      

  7.   

    相同查询结果不同SQL语句,如何判断其效率?
    --查看计划
    SET SHOWPLAN_ALL ON;SET SHOWPLAN_ALL OFF; /*
    注意PhysicalOP,通过EstimateIO、EstimateCPU等得到更确切的数据描述。
    */
      

  8.   

    set showplan_all on设置查询计划了。