我想用下面的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
and e.provinceid = '19'
and p.id = 1
group by to_char(t.t_checktime, 'mm')) t
on t.checktime = m.s_date
order by m.s_date asc;
执行计划
----------------------------------------------------------
Plan hash value: 2247359995
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 29 | 3382 (1)| 00:00:41 |
| 1 | SORT ORDER BY | | 1 | 29 | 3382 (1)| 00:00:41 |