解决方案 »

  1.   

    select 日期,新增用户数,
    (select count(*) from user where date(register_time)=date(a.register_time) and exists (select 1 from log_login where uid=user.uid and login_time>=date(register_time)+interval 1 day))/新增用户数 as 次日留存,
    (select count(*) from user where date(register_time)=date(a.register_time) and exists (select 1 from log_login where uid=user.uid and login_time>=date(register_time)+interval 2 day))/新增用户数 as `2日留存`,
    from
    (
    select date(register_time) as 日期,count(*) as 新增用户数
    from user
    group by date(register_time)
    ) a
      

  2.   

    数据量稍微大点(user表5万条数据 log_login表 10万条数据)查询速度就变很慢,还有没有优化空间。登录日志表的数量增加的比较快
      

  3.   

    1 PRIMARY <derived4> ALL 8
    4 DERIVED user ALL 66358 Using where; Using temporary; Using filesort
    2 DEPENDENT SUBQUERY user ALL 66358 Using where
    3 DEPENDENT SUBQUERY log_login ALL 33809 Using where
      

  4.   

    1 PRIMARY <derived4> ALL 8
    4 DERIVED user ALL 66358 Using where; Using temporary; Using filesort
    2 DEPENDENT SUBQUERY user ALL 66358 Using where
    3 DEPENDENT SUBQUERY log_login ALL 33809 Using where
    给表字段增加索引就解决了