我们首先获取当前日期-
mysql> select curdate();
这将产生以下输出-
+------------+ | curdate() | +------------+ | 2019-12-15 | +------------+ 1 row in set (0.00 sec)
让我们首先创建一个表-
mysql> create table DemoTable1956 ( ProductId int, ProductName varchar(20), CustomerName varchar(20), ShippingDate date );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1956 values(101,'Product-1','Sam','2019-10-11'); mysql> insert into DemoTable1956 values(102,'Product-2','Carol','2018-12-01'); mysql> insert into DemoTable1956 values(103,'Product-3','David','2019-12-15'); mysql> insert into DemoTable1956 values(104,'Product-4','Robert','2019-12-16');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1956;
这将产生以下输出-
+-----------+-------------+--------------+--------------+ | ProductId | ProductName | CustomerName | ShippingDate | +-----------+-------------+--------------+--------------+ | 101 | Product-1 | Sam | 2019-10-11 | | 102 | Product-2 | Carol | 2018-12-01 | | 103 | Product-3 | David | 2019-12-15 | | 104 | Product-4 | Robert | 2019-12-16 | +-----------+-------------+--------------+--------------+ 4 rows in set (0.00 sec)
这是选择列并获取当前日期和下一个日期记录的查询-
mysql> select CustomerName from DemoTable1956 where ShippingDate IN(CURDATE(),CURDATE()+interval 1 Day);
这将产生以下输出-
+--------------+ | CustomerName | +--------------+ | David | | Robert | +--------------+ 2 rows in set (0.00 sec)