有如下sql语句:select count(1)
  from t_project_one_estimate t
 where exists (select t1.statistic_id
          from t_project_one_estimate t1
         where t1.statistic_close_state = 2);表t_project_one_estimate现在有一千多万条数据,每条数据都有状态,现在要查询是否存在状态为2的,如果存在就可以返回了,我写了如上sql语句但是查询速度很慢,现在请问下各位大哥,怎么优化下才能提升效率啊,或者其它方法也可以,小弟先谢谢各位了。只要说的有道理就给分。

解决方案 »

  1.   

    如果只是判断是否存在而不需要统计共有多少条的话,可以用下面的:select count(1)
      from dual
     where exists (select 1
              from t_project_one_estimate t1
             where t1.statistic_close_state = 2);
      

  2.   

    因为在exist中不需要有返回。。所以都是用select 1 from
      

  3.   

    select count(1) from t_project_one_estimate t1
    where t1.statistic_close_state = 2
    and rownum = 1;
      

  4.   

    select count(1)
      from t_project_one_estimate t1
     where t1.statistic_close_state = 2 and rownum=1
    会不会好点?
      

  5.   

    不是专业人员,只是想问一下,为啥写成这 样?
    照LZ的意思 是不是直接 select 1
      from t_project_one_estimate 
     where statistic_close_state = 2就行了?
    ‘ilovemk’哥(姐)你 说说。。
      

  6.   

    这样写会把所有statistic_close_state = 2的记录读出来,效率不高。