是个公司的项目,我现在把问题简化一下,已知一个表Acreate table A
{
  user_id varchar(10) primary key, #用户ID
  tradetime int(10) not null #交易时间,为UNIX时间
};那么我的将会使用一条select语句计算每个用户id号出现的次数和出现的天数,如下
select user_id, count(*), count(distinct from_unixtime(tradetime, ‘%Y%m%d'))
from A
group by user_id;这条语句是可以执行的,首先说明下,我的数据量是在百万级别的,这条语句用时将近30多分钟,后来我把distinct去掉后速度明显加快,只耗时1分钟左右,我认为瓶颈是distinct,因为distinct可能会进行海量数据的排序。我看现在只有改变我写的sql语句的,大伙可以写出满足功能的语句,使速度得到明显提升吗,谢谢了