表 CREATE TABLE `ch1` ( `id` int(10) unsigned zerofill NOT NULL AUTO_INCREMENT, `no` int(10) unsigned DEFAULT NULL, `dtime` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) 查询语句 select sum(no) as number,dtime as date from ch1 group by month(dtime) 数据大约1000w条记录,需要40秒,感觉太慢了,有什么解决办法?需要在dtime上创建一个索引。
create index idx_dtime on ch1(dtime); 如果只是这条语句的话,在dtime上建立索引试试 楼上的方法 分组列上建索引 group by month(dtime)
这个建个索引就OK了啊 同意诸位意见! 建立索引之后大约需要多少时间? 索引不起任何左右 这是分析执行语句的时候的结果 Extra: Using temporary; Using filesort 索引不起任何左右 这是分析执行语句的时候的结果 Extra: Using temporary; Using filesort select sum(
先上错误 无法联接数据库 java.sql.SQLException: Before start of result set at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910) at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java: ......