4

So I have an image uploader, and I want to create a minimal bot protection. My table structure looks like this:

| ID | uploader_ip | image_name | image_url_id | date
------------------------------------------------------
| 1  | 127.0.0.1   | bla.jpg    | fsdJGf       | UNIX Timestamp  (UPDATE ON: Create)

I want to check if there are more or exactly 50 images/rows, that were created in less or exactly two minutes.

How can I do that?

4

2 回答 2

0

您需要构建一个包含计数和组的查询,并在日期列上放置一个范围。如果您只在最近两分钟内执行此操作,您的查询将如下所示:

select count(*) from your_table where uploader_ip="<some ip>" and date > (now() - interval 2 minute) group by uploader_ip;
于 2013-10-10T18:07:25.367 回答
-1

这是查询

Select count(*) from table 
where 
table.date >  now() - interval 2 minute
-- or the function date_sub(now(), interval 2 minute)
and id = 1

如果您想要在 2 分钟窗口内上传的所有用户 ID:

select id, 
  (select count(*) 
    from table 
    where id = t.id 
    and date > t.date - interval 1 minute 
    and date < t.date + interval 1 minute
  ) as total
from table t
where total >= 50
于 2013-10-10T18:07:02.253 回答