A表如下,还有自动增长的字段及其他不重要的字段。表约有两千五百万条记录。sid | op | code
3 | 1 | -199
1 | 2 | 0
11 | 1 | 1
3 | 2 | 0我想查询出code为0,op为1的sid的个数,我写的sql语句如下:select sid,count(*) as num from A where code=0 and op=1 group by sid order by num desc limit 10;这个执行时间要30秒。。时间太长了,求优化
3 | 1 | -199
1 | 2 | 0
11 | 1 | 1
3 | 2 | 0我想查询出code为0,op为1的sid的个数,我写的sql语句如下:select sid,count(*) as num from A where code=0 and op=1 group by sid order by num desc limit 10;这个执行时间要30秒。。时间太长了,求优化
KEY `sid` (`sid`),
) ENGINE=InnoDB AUTO_INCREMENT=22241971 DEFAULT CHARSET=utf8 | op有两种值,code有3种。