select count(id) as ct,case when to_char(Sysdate,'YYYY-MM-DD')=to_char(Systime,'YYYY-MM-DD') then 1 else 0 end as flag from statistics where 1=1 group by case when to_char(Sysdate,'YYYY-MM-DD')=to_char(Systime,'YYYY-MM-DD') then 1 else 0 end order by flag如何通过修改SQL语句或者建立索引提高执行速度
谢谢

解决方案 »

  1.   

    select count(id) as ct, decode((sysdate - systime), 0, 1, 0) flag
      from statistics
     where 1 = 1
     group by decode((sysdate - systime), 0, 0, 1)
     order by flaggroup最好换成其他的。
      

  2.   


    select count(id),
           decode(to_char(Sysdate, 'YYYYMMDD') - to_char(Systime, 'YYYYMMDD'),
                  0,
                  1,
                  0) de
      from statistics
     where 1 = 1
     order by de
     group by de;