需要在31月23日23:59:59(月底)查找状态为1的所有用户列表的建议。mysql:在特定时间获取数据
select count(*) from users where status=1 and created_at=?
需要在31月23日23:59:59(月底)查找状态为1的所有用户列表的建议。mysql:在特定时间获取数据
select count(*) from users where status=1 and created_at=?
将数据库恢复到前一次的一种方法是将binlog反向运行到当前数据库状态。
或
启动数据库模式并运行与仅与表相关的binlog中的所有语句。
采取奴隶的帮助,如果仍有一些以前的状态
以下语法会给有状态= 1的任何用户,并且是在31创建:一月的ST 2014
select count(*)
from users
where status=1 and DATE(created_at)='2014-01-31'
这种语法将给具有准确时间'2014-01-31 23:59:59'的用户。假设dateformat是相同的。似乎用户在那个时候创建了unlikley。
select count(*)
from users
where status=1 and created_at='2014-01-31 23:59:59'
select
count(*)
from
users
where status=1 and
created_at = concat(last_day(curdate(), ' 23:59:59'));
last_day()
功能here如果使用Linux服务器,然后通过cronjob-
保存安排如下脚本低于user.sh文件中的行。
六user.sh
#!/bin/bash
DBUSER=your_server_user
DBPASS=your_server_pass
mysql -u$DBUSER -p$DBPASS db_name -e "select count(*) from users where status=1;" >> user.xls
echo -e "Please get the attached user Report." | mail -s"user Report" -a user.xls [email protected]
现在cron利用此脚本 -
crontab -e命令
59 23 31 1 * /script_path/user.sh
将在23:59执行31,扬并将用户报告发送到您的邮件ID。
如果您使用的是Windows服务器,那么您可以创建一个批处理文件并在Windows任务调度的帮助下调用它。
在你提到的一个表中存储历史用户更新的评论。您可以使用此表来检查谁在那个时候有状态1用户:
SELECT COUNT(DISTINCT user_id) AS users
FROM status_history sh
WHERE
sh.created = (SELECT MAX(sx.created)
FROM status_history sx
WHERE sx.user_id = sh.user_id
AND sx.created < '2014-01-31 23:59:59')
AND sh.status = 1
我们做一个内部的选择,以获得每个状态和用户的最新状态更改日期和抓住历史与日期。然后,我们计算任何状态为1
的人。显然,如果你的表格模式不同,你可能需要调整上述内容。
现在状态改变了吗? – avisheks
是@avisheks状态可以在下个月更改。需要查找所有用户的31个1月状态 – jacob21
您是否在某处维护用户状态更改的历史记录? – rakeshjain