求条SQL

cooledit2730 2010-03-02 09:38:25
查询一段时间内每天一个时间段的注册人数
比如1-10号 每天12:00到14:00的注册人数
explain select count(user_id) as register,count(distinct logon_ip) as register_ip ,date(add_date) as register_date from user
where add_date > '2009-12-01 00:00:00' and add_date <'2010-03-01 00:00:00' and time(add_date)>'12:00:00' and time(add_date)<'14:00:00'
group by register_date order by register limit 0,10

执行效率较低。速度很慢 如何优化?
1 SIMPLE user ALL \N \N \N \N 4009553 Using where; Using temporary; Using filesort

...全文
82 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cooledit2730 2010-03-02
  • 打赏
  • 举报
回复





cooledit2730 2010-03-02
  • 打赏
  • 举报
回复
除了建索引外 这条SQL还有其他需要优化的地方吗?
WWWWA 2010-03-02
  • 打赏
  • 举报
回复
引用 4 楼 cooledit2730 的回复:


意思就是建索引?

yes
cooledit2730 2010-03-02
  • 打赏
  • 举报
回复


意思就是建索引?


WWWWA 2010-03-02
  • 打赏
  • 举报
回复
主要是加速WHERE速度
cooledit2730 2010-03-02
  • 打赏
  • 举报
回复
暂时没有建索引

如果不在ADD_DATE字段创建索引的话
是不是用子查询也是跟上面的SQL一样的效率
WWWWA 2010-03-02
  • 打赏
  • 举报
回复
add_date上建立索引没有
zhuzhupj 2010-03-02
  • 打赏
  • 举报
回复
学习下!还没考虑过优化!

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧