我在MySQL中遇到了一个问题。我想要获取两个日期-时间条目之间的记录计数。
例如:
我的表中有一个名为'created‘的列,其数据类型为datetime。
我想计算在“今天凌晨4:30”和“当前日期时间”之间创建的日期-时间的记录。
我尝试了MySQL的一些功能,但仍然没有成功。
你能帮我一下吗?谢谢。
发布于 2011-04-26 14:20:14
可能存在以下情况:
SELECT count(*) FROM `table`
where
created_at>='2011-03-17 06:42:10' and created_at<='2011-03-17 07:42:50';或者使用between
SELECT count(*) FROM `table`
where
created_at between '2011-03-17 06:42:10' and '2011-03-17 07:42:50';您可以根据需要更改日期时间。可以使用curdate()或now()来获取所需的日期。
发布于 2011-04-26 14:19:53
select * from yourtable where created < now() and created > '2011-04-25 04:00:00'发布于 2011-04-26 14:25:10
select * from yourtable
where created < now()
and created > concat(curdate(),' 4:30:00 AM') https://stackoverflow.com/questions/5786649
复制相似问题