选择除今天以外的所有行?
让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Name varchar(100), -> DueDate datetime -> );
使用insert命令在表中插入一些记录。假设当前日期为“2019-07-03”-
mysql> insert into DemoTable values('Chris','2019-06-24'); mysql> insert into DemoTable values('Chris','2018-01-01'); mysql> insert into DemoTable values('Robert','2019-07-03'); mysql> insert into DemoTable values('Carol','2019-08-03');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
这将产生以下输出-
+--------+---------------------+ | Name | DueDate | +--------+---------------------+ | Chris | 2019-06-24 00:00:00 | | Chris | 2018-01-01 00:00:00 | | Robert | 2019-07-03 00:00:00 | | Carol | 2019-08-03 00:00:00 | +--------+---------------------+ 4 rows in set (0.00 sec)
这是查询以选择除今天以外的所有行-
mysql> select *from DemoTable where date(DueDate) !=curdate();
输出结果
这将产生以下输出-
+-------+---------------------+ | Name | DueDate | +-------+---------------------+ | Chris | 2019-06-24 00:00:00 | | Chris | 2018-01-01 00:00:00 | | Carol | 2019-08-03 00:00:00 | +-------+---------------------+ 3 rows in set (0.00 sec)