MYSQL在这一天内选择日期(MYSQL select where date within this day)

编程入门 行业动态 更新时间:2024-10-27 00:33:18
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.

更多推荐

本文发布于:2023-07-16 10:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126890.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在这   日期   MYSQL   day   date

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!