select d,sum(x1),sum(x2) from ( select date(created_at) as d ,(select 1 from 用户登陆表 where uid=a.uid and login_at>a.created_at + interval 1 day) as x1 ,(select 1 from 用户登陆表 where uid=a.uid and login_at>a.created_at + interval 3 day) as x3 from 用户注册表 a where created_at between '2014-05-02' and '2014-05-06' ) t group by d
会报错,提示:subquery returns more than one row
贴建表及插入记录的SQL,及要求结果出来看看
select d,sum(x1),sum(x2) from ( select date(created_at) as d ,(select if(count(*) > 0, 1, 0) from u_l where uid=a.uid and login_at >= a.created_at + interval 1 day) as x1 ,(select if(count(*) > 0, 1, 0) from u_l where uid=a.uid and login_at >= a.created_at + interval 3 day) as x2 from u_c a where created_at between '2014-05-02' and '2014-05-06') t group by d
from (
select date(created_at) as d
,(select 1 from 用户登陆表 where uid=a.uid and login_at>a.created_at + interval 1 day) as x1
,(select 1 from 用户登陆表 where uid=a.uid and login_at>a.created_at + interval 3 day) as x3
from 用户注册表 a
where created_at between '2014-05-02' and '2014-05-06'
) t
group by d
会报错,提示:subquery returns more than one row
select date(created_at) as d
,(select if(count(*) > 0, 1, 0) from u_l where uid=a.uid and login_at >= a.created_at + interval 1 day) as x1
,(select if(count(*) > 0, 1, 0) from u_l where uid=a.uid and login_at >= a.created_at + interval 3 day) as x2
from u_c a where created_at between '2014-05-02' and '2014-05-06') t group by d