MySQL INTERVAL分钟 [英] MySQL INTERVAL Mins
本文介绍了MySQL INTERVAL分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用此查询获取2小时或更长时间的所有记录:
I am trying to get the all records which are 2 hours or more old using this query:
$minutes = 60 * 2
SELECT COUNT(id) AS TOTAL, job_id
from tlb_stats
WHERE log_time >= DATE_SUB(CURRENT_DATE, INTERVAL $minutes MINUTE)
GROUP BY job_id
它仅选择最近的记录,并跳过旧的记录.当我更改log_time <= ...
时,它只会选择旧的而跳过新的.
It only selects the recent records and skips the old. When I change log_time <= ...
it only selects old and skips which are the new one.
我在做什么错了?
推荐答案
尝试:
$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`
- 使用反引号对字段进行引号(例如"total"和"id"之类的词可能有朝一日在MySQL中表示"意思")
- 在CURRENT_DATE使用
NOW()
表示2010-08-04,不包括时间 - 使用
<
获取早于该日期的条目 . - 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.
这篇关于MySQL INTERVAL分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文