且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

允许用户每小时提交一次他们提交的输入?

更新时间:2023-09-30 15:11:52

然后使用如下的查询:


INSERT INTO CODES (code) 
  VALUES (555)
  ON DUPLICATE KEY UPDATE lastUpdated = 
               case when NOW() - INTERVAL 5 MINUTE > lastUpdated 
                  then NOW() 
                  else lastUpdated end

只有在超过5分钟的情况下,才会更新lastUpdated字段

this will update the lastUpdated field only in cases when it's older than 5 minutes