为此,您可以使用CURTIME()。让我们首先创建一个表-
create table DemoTable -> ( -> ArrivalTime timestamp -> );
使用插入命令在表中插入一些记录-
insert into DemoTable values('2019-10-26 17:55:55'); insert into DemoTable values('2019-10-26 18:00:00'); insert into DemoTable values('2019-10-26 18:55:00'); insert into DemoTable values('2018-10-26 16:00:10');
使用select语句显示表中的所有记录-
select *from DemoTable;
这将产生以下输出-
+---------------------+ | ArrivalTime | +---------------------+ | 2019-10-26 17:55:55 | | 2019-10-26 18:00:00 | | 2019-10-26 18:55:00 | | 2018-10-26 16:00:10 | +---------------------+ 4 rows in set (0.00 sec)
当前时间如下-
select curtime(); +-----------+ | curtime() | +-----------+ | 18:43:55 | +-----------+ 1 row in set (0.00 sec)
以下是查询以选择当前小时中时间戳的位置-
select *from DemoTable where hour(ArrivalTime)=hour(curtime());
这将产生以下输出-
+---------------------+ | ArrivalTime | +---------------------+ | 2019-10-26 18:00:00 | | 2019-10-26 18:55:00 | +---------------------+ 2 rows in set (0.00 sec)