如何选择MySQL中除今日之外的所有行?
我们先创建一个表 ——
mysql> create table DemoTable -> ( -> Name varchar(100), -> DueDate datetime -> ); Query OK, 0 rows affected (0.54 sec)
使用 insert 命令向该表中插入一些记录。假定今天的日期是“2019-07-03”——
mysql> insert into DemoTable values('Chris','2019-06-24'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Chris','2018-01-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Robert','2019-07-03'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Carol','2019-08-03'); Query OK, 1 row affected (0.22 sec)
使用 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)
广告