MYSQL在这一天内选择日期(MYSQL select where date within this day)
我的查询看起来像这样:
SELECT COUNT(entryID) FROM table WHERE date >= DATE_SUB(CURDATE(), INTERVAL 1 DAY)这是否会计算date值在一天内的行(从12:00开始;而不是在24小时内)? 如果不是,我该怎么做?
MY query looks like this:
SELECT COUNT(entryID) FROM table WHERE date >= DATE_SUB(CURDATE(), INTERVAL 1 DAY)Will this count the rows whose date values are within the day (starting at 12:00; not within 24 hours)? If not, how do I do so?
最满意答案
以下内容应足以在当天获得记录:
SELECT COUNT(entryID) FROM table WHERE date >= CURDATE()正如Michael在评论中指出的那样,它会在最近两天内以当前形式查看所有记录。
如果date实际上是一个datetime - 如果它只是一个date类型, =应该就足够了,那么只需要>=运算符。
The following should be enough to get records within the current day:
SELECT COUNT(entryID) FROM table WHERE date >= CURDATE()As Michael notes in the comments, it looks at all records within the last two days in its current form.
The >= operator is only necessary if date is actually a datetime - if it's just a date type, = should suffice.
更多推荐
发布评论