Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试实施系统范围的登录限制,我需要计算过去 3 个月的每日平均登录尝试失败次数。
我目前在每次登录失败时插入一条记录,每条记录都有一个时间戳。我怎样才能在 MySQL 中做到这一点?
在此先感谢您的帮助
SELECT AVG(cnt) FROM (SELECT COUNT(*) AS cnt FROM mytable WHERE `date` BETWEEN DATE_SUB(NOW(), INTERVAL 3 MONTH) AND NOW() GROUP BY DATE(`date`)) x
假设您有一个mytable字段date类型为 的表date,datetime或者timestamp
mytable
date
datetime
timestamp