【发布时间】:2013-08-11 16:38:03
【问题描述】:
我想知道 6 月和 7 月有多少用户注册,这是我写的第一个查询:
select count(*) from users where created_at>="2013-06-01" and created_at<="2013-07-31"
结果:15,982
select count(*) from users where year(created_at)=2013 and month(created_at) in (6,7)
结果:16,278
为什么它们返回不同的结果?有人可以解释一下吗?还是我错过了什么?
谢谢。
【问题讨论】:
-
created_at 列的类型是什么?如果它碰巧是基于字符的列而不是日期列,则可能无法按预期进行比较。
标签: mysql date date-range