一、前提
1、MySQL版本信息:
MySQL版本:8.0.27
注意:其他版本(主要5.x版本未验证)
2、表字段:
定义列
create_time datetime null comment '创建时间'
id | create_time |
---|---|
1 | 2022-04-01 23:00:00 |
2 | 2022-04-02 00:00:00 |
3 | 2022-04-02 00:00:01 |
4 | 2022-04-02 12:34:56 |
5 | 2022-04-02 23:59:59 |
6 | 2022-04-03 00:00:00 |
二、使用>、<、>=、<=比较
1. >比较
a) > 日期
select * from tab_a as t where t.create_time > '2022-04-02'
结果集:
id | create_time |
---|---|
3 | 2022-04-02 00:00:01 |
4 | 2022-04-02 12:34:56 |
5 | 2022-04-02 23:59:59 |
6 | 2022-04-03 00:00:00 |
b) > 时间
select * from tab_a as t where t.create_time > '2022-04-02 00:00:00'
结果集:
id | create_time |
---|---|
3 | 2022-04-02 00:00:01 |
4 | 2022-04-02 12:34:56 |
5 | 2022-04-02 23:59:59 |
6 | 2022-04-03 00:00:00 |