各位,谁能帮我看下这段SQL如何优化下运行速度?

[复制链接]
查看11 | 回复3 | 2011-7-13 15:56:16 | 显示全部楼层 |阅读模式
select to_char(createtime, 'YYYYMMDD'), count(*)
from ai_visit_record
where to_char(createtime, 'YYYYMMDD') in

(20110406, '20110407', '20110408')
group by to_char(createtime, 'YYYYMMDD')
order by to_char(createtime, 'YYYYMMDD') asc

回复

使用道具 举报

千问 | 2011-7-13 15:56:16 | 显示全部楼层
task_contentid in(select distinct(tx_id) from gis_qx_fw where YH_ID = '00000000000034') orsubstr(task_contentid,0,instr(task_contentid,'/')-1) in (select distinct(tx_id)from gis_qx_fw where YH_ID = '00000000000034'))这种写法会很慢的。你可以先把这些数据筛选出来放在一张temp表里面,然后再跑整个sql。...
回复

使用道具 举报

千问 | 2011-7-13 15:56:16 | 显示全部楼层
我觉的你这个语句没有办法优化了,如果速度太慢还得从表设计上下手,加个索引吧...
回复

使用道具 举报

千问 | 2011-7-13 15:56:16 | 显示全部楼层
如果可以用临时表的话先用临时表读取数据,在进行查询和分组动作,或者select to_char(A.createtime, 'YYYYMMDD'), count(*)from (select t1.createtime from ai_visit_record as t1 where createtime in ('2011-04-06','20...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行