Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么会这样
此查询不应该检索特定日期之前的记录数吗?
SELECT count(*) FROM `posts` WHERE date < 2013-01-01
我在数据库上有几条与查询匹配的记录,但是,计数为 0
我究竟做错了什么??
您需要使用将您的字符串定义为日期DATE
DATE
SELECT count(*) FROM posts WHERE date < DATE('2013-01-01')
SELECT count(*) FROM `posts` WHERE `date` < '2013-01-01'
如果日期列的日期格式与 where 子句中的不同,则使用 FORMAT_DATE 函数使它们相似。