mysql查询在2019年3月注册的用户,在往后的一年时间(按月),的活跃或流失情况——生命周期
现有2张表
user:
created_at:注册日期
user:
Action:活跃行为
CreateTime:活跃发生时间
以下是本人写的sql
select
t2.'日期',
count(t1.user_openid)
from
(
select
user_openid,
DATE_FORMAT(created_at, '%Y-%m') AS `日期`,
from fi_user
where substr(created_at,1,7) = '2019-03'
) as t1
left join
(
select
UserID,
# ActionContent,
DATE_FORMAT(CreateTime, '%Y-%m') AS `日期`,
from fi_user_action
where substr(CreateTime,1,7) >= '2019-03'
#where TO_DAYS(CreateTime) >= TO_DAYS('2019-03')
) as t2
on t1.user_openid = t2.UserID
group by t2.`日期`
然后报了错:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''日期',
count(DISTINCT t2.UserID)
求助各位,如果我写的sql逻辑符合我的需求,那么我这个报错怎么改?
如果写的逻辑不正确,我应该怎么改写?
(补充)预期结果:
| 日期 | 用户数 |
| ------- | ------ |
| 2019-03 | 4 |
| 2019-04 | … |
| … | |
| 2020-03 | |
总结一下问题:
需求:查询2019年3月注册的用户,在往后一年(按月)的时间中的活跃数。
逻辑:
1.查询2019年3月注册的用户数
2.查询此部分用户,在往后一年中的活跃情况
3.日期从2019年3月开始,逐月返回,直到2020年3月。
预期结果:
| 日期 | 用户数 |
| ------- | ------ |
| 2019-03 | 4 |
| 2019-04 | … |
| … | |
| 2020-03 | 1 |