我希望在选择的日期范围内获得在我的网站注册的用户总数,如下所示:
然后我需要计算
6月1日为2
6月2日为3
6月3日为5
这是我的查询
SET @runtot:=0;
SELECT
count(u.app_user_registered_date) as users_count,
(@runtot := count(u.app_user_registered_date) + @runout) AS rt,
date(u.app_user_registered_date) as registered_date
FROM entr_user as u
INNER JOIN entr_app_granted_permission_details as g
ON g.device_id=u.device_id
WHERE date(u.app_user_registered_date) between '2016-05-31' and '2016-06-03'
GROUP BY date(u.app_user_registered_date) ORDER BY u.app_user_registered_date;
但这里的rt值为NULL
答案 0 :(得分:1)
也许你需要rt。人们无法分辨。但是,您的变量中似乎存在拼写错误: runtot 。据推测,您想写: runout 。这就是为什么rt返回null。这里:
com
答案 1 :(得分:0)
像这样使用.. 当天的总用户数
SELECT u.app_user_registered_date,COUNT(u.id) as users FROM `entr_user` as u
INNER JOIN entr_app_granted_permission_details as g ON g.device_id=u.device_id
WHERE date(u.app_user_registered_date) between '2016-06-07' and '2016-06-10' GROUP BY u.app_user_registered_date
当天及之前的总用户数,直至from_date我们提供的内容
SELECT u.app_user_registered_date,COUNT(u.id) as users,
(select COUNT(h.id) from entr_user as h
INNER JOIN entr_app_granted_permission_details as i ON i.device_id=h.device_id
where (DATE(h.app_user_registered_date) between '2016-06-07' and '2016-06-10') and
DATE(h.app_user_registered_date)<=DATE(u.app_user_registered_date)
)as total_users
FROM `entr_user` as u
INNER JOIN entr_app_granted_permission_details as g ON g.device_id=u.device_id
WHERE date(u.app_user_registered_date) between '2016-06-07' and '2016-06-10' GROUP BY u.app_user_registered_date