检查是否在最近的x秒内添加了mySQL记录 [英] Check if mySQL record added in the last x seconds

查看:70
本文介绍了检查是否在最近的x秒内添加了mySQL记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mySQL数据库和一个表,用于在其中创建项目的新记录.创建的每个项目都有一个项目名称"和一个事件创建日期(类型为DATETIME).

I have a mySQL database and a table where new records for a project are created. Each project created has a "project name" and an event created date (of type DATETIME).

可以使用相同的名称创建两个项目,但是如果它们是由同一用户快速连续创建的,则可以肯定地认为这是用户方面的错误(单击两次,在事件变量发生时刷新浏览器)已通过等).

There can be two projects created with the same name, but if they get created by the same user in quick succession, it is safe to assume it was a mistake on the user's part (clicking twice, refreshing the browser when event variables are passed, etc.).

如何编写SQL语句以检查是否已存在同名记录,该记录是在最近10秒钟内添加的?到目前为止,尽管我不知道如何检查最近10秒钟,我还是有以下内容.

How do I write a SQL statement to check if a record with the same name already exists, it was added in the last 10 seconds? So far I have the following, although I don't know how to check for the last 10 seconds.

select * from projects where user = 'johnsmith' AND projectname = 'test' AND active='y' AND DATE(projectcreatedon) = CURRENT_DATE AND DATEPART() < ....?

推荐答案

replace AND DATE(projectcreatedon)= CURRENT_DATE AND DATEPART()< ....?与:

replace AND DATE(projectcreatedon) = CURRENT_DATE AND DATEPART() < ....? with:

AND projectcreatedon > (now() - INTERVAL 10 SECOND)

这篇关于检查是否在最近的x秒内添加了mySQL记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆