使用INTERVAL添加天数后,MySQL查询获取的日期记录大于当前日期?
让我们首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, AddDay int, PostDate date );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(AddDay,PostDate) values(20,'2019-08-04'); mysql> insert into DemoTable(AddDay,PostDate) values(7,'2019-08-20'); mysql> insert into DemoTable(AddDay,PostDate) values(45,'2019-07-01');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----+--------+------------+ | Id | AddDay | PostDate | +----+--------+------------+ | 1 | 20 | 2019-08-04 | | 2 | 7 | 2019-08-20 | | 3 | 45 | 2019-07-01 | +----+--------+------------+ 3 rows in set (0.00 sec)
这是从AddDay列添加天后获取大于当前日期的数据记录的查询-
mysql> select *from DemoTable where PostDate +interval AddDay day >=curdate();
这将产生以下输出-
+----+--------+------------+ | Id | AddDay | PostDate | +----+--------+------------+ | 1 | 20 | 2019-08-04 | | 2 | 7 | 2019-08-20 | +----+--------+------------+ 2 rows in set (0.00 sec)
热门推荐
10 祝福语简短创意闺蜜
11 新年祝福语简短创意兄弟
12 对睡觉的祝福语简短
13 新年祝福语长辈简短红包
14 新房开工文案祝福语简短
15 生日祝福语男孩 简短独特
16 档案调动孩子祝福语简短
17 生日祝福语简短明了 同事
18 妈妈生日贺卡祝福语 简短