MySQL INTERVAL Mins

て烟熏妆下的殇ゞ 提交于 2019-12-03 07:25:45
mvds

Try:

$minutes = 60 * 2

SELECT COUNT(`id`) AS `TOTAL`, `job_id` 
  FROM `tlb_stats` 
  WHERE `log_time` < DATE_SUB(NOW(), INTERVAL $minutes MINUTE) 
  GROUP BY `job_id`
  • use backticks to quote fields (words like "total" and "id" may someday mean something in MySQL)
  • use NOW() for CURRENT_DATE just means 2010-08-04, not including the time
  • use < to get entries older than that date.
DeathRs
SELECT * FROM `table_name` WHERE CURTIME() >= (`colname` + INTERVAL 120 MINUTE)

Here, colname is the column where you added timestamp at the time when the record was created.

You can also do it in this way:

$minutes = 60 * 2

SELECT COUNT(`id`) AS `TOTAL`,
       `job_id` 
FROM `tlb_stats` 
WHERE `log_time` < NOW() - INTERVAL $minutes MINUTE
GROUP BY `job_id`
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!