日期:2014-05-17  浏览次数:20851 次

新手请教啊,求各位进来看看~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我想用下面的sql统计出一年12个月体温正常的人数作为报表,但是查询速度要十秒,谁能帮我优化一下啊?谢谢~~
       with m as
         (select rownum s_date from dual connect by rownum between 1 and 12)
        select m.s_date,
               case
                 when t.num is null then
                  0
                 else
                  t.num
               end
          from m
          left outer join (select count(*) num, 
                                   to_char(t.t_checktime, 'mm') as checktime
                             from temperature    t,
                                  students        s,
                                  eduorganization e  ,
                                  province p
                            where t.t_checktime >=  to_date( '2013-01-01 00:00:00' ,'yyyy-mm-dd hh24:mi:ss')  
                              and t.t_checktime < to_date( '2013-12-31 23:59:59' ,'yyyy-mm-dd hh24:mi:ss')
                              and t.temperature >= 36 and t.temperature <= 37.5
                              and t.stu_obid = s.id
                              and s.organization_obid = e.id  
    &n