在MySQL中显示从当前日期到当月剩余的记录?
让我们首先创建一个表-
create table DemoTable ( BookingDate date );
使用插入命令在表中插入一些记录-
insert into DemoTable values('2019-09-21'); insert into DemoTable values('2018-09-10'); insert into DemoTable values('2019-09-10'); insert into DemoTable values('2019-09-08'); insert into DemoTable values('2016-09-18');
使用select语句显示表中的所有记录-
select *from DemoTable;
这将产生以下输出-
+-------------+ | BookingDate | +-------------+ | 2019-09-21 | | 2018-09-10 | | 2019-09-10 | | 2019-09-08 | | 2016-09-18 | +-------------+ 5 rows in set (0.00 sec)
以下是MySQL中从当前日期到当月剩余时间的查询-
select *from DemoTable where BookingDate between curdate() and last_day(curdate());
这将产生以下输出-
+-------------+ | BookingDate | +-------------+ | 2019-09-21 | | 2019-09-10 | | 2019-09-08 | +-------------+ 3 rows in set (0.01 sec)