select so.userid,sum(so.price) as price,count(so.orderid) as num from so
where so.deleteflag = 0 and so.createdate>='2008-05-01 00:00:00'
and so.createdate<'2008-06-01 00:00:00' group by so.userid order by num desc这个是SQL语句,
数据总共只有6万条的样子,但是查询的速度很慢,有什么方法可以让速度变快?
where so.deleteflag = 0 and so.createdate>='2008-05-01 00:00:00'
and so.createdate<'2008-06-01 00:00:00' group by so.userid order by num desc这个是SQL语句,
数据总共只有6万条的样子,但是查询的速度很慢,有什么方法可以让速度变快?
deleteflag
createdate[align=center]==== 思想重于技巧 ====
[/align]
之后的数据量是多少?多少记录?[align=center]==== 思想重于技巧 ====
[/align]
userid有INDEX吗?[align=center]==== 思想重于技巧 ====
[/align]
2、加大tmp_table_size系统变量的值。
where so.deleteflag = 0 and so.createdate>='2008-05-01 00:00:00'
and so.createdate <'2008-06-01 00:00:00' group by so.userid order by num desc ;
执行后,看看有没有可以优化的地方。