mysql 时差

发布于 2024-11-28 03:17:49 字数 184 浏览 3 评论 0原文

我正在尝试用 mysql 做一些垃圾邮件过滤器。我想检查用户在表中创建的最后一条记录并将其与当前时间进行比较。创建的时间以 mysql datetime 格式存储为 date_created

我已经尝试过TIMEDIFF(),但我无法让它为我工作,请帮助。

I am trying to do a little spam filter with mysql. I want to check the last record a user has created in a table and compare it to the current time. The time created is stored as date_created with mysql datetime format.

I have tryed TIMEDIFF(), but I can't get it to work for me, please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

堇色安年 2024-12-05 03:17:49
 SELECT count(*) FROM database WHERE date_created> NOW() - INTERVAL 1 HOUR AND user_id=17

如果此查询返回非零值,则存在该用户在上一小时创建的行

 SELECT count(*) FROM database WHERE date_created> NOW() - INTERVAL 1 HOUR AND user_id=17

If this query returns non-zero value, then there are rows, created on last hour by this user

风向决定发型 2024-12-05 03:17:49

获取用户x的最新记录和与当前时间的时间差异

SELECT
  tab.*,
  TIMEDIFF(NOW(), date_created) as diff
FROM tab
WHERE(userid = x)
ORDER BY date_created DESC
LIMIT 1

To get the most recent record and time diff to current time for user x

SELECT
  tab.*,
  TIMEDIFF(NOW(), date_created) as diff
FROM tab
WHERE(userid = x)
ORDER BY date_created DESC
LIMIT 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文