从带有日期记录的列中显示MySQL中的不同日期
首先让我们创建一个表 –
mysql> create table DemoTable
(
AdmissionDate datetime
);
Query OK, 0 rows affected (8.99 sec)
使用插入命令在表中插入一些记录 –
mysql> insert into DemoTable values('2010-01-10 12:30:45');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('2010-01-10 12:30:45');
Query OK, 1 row affected (0.46 sec)
mysql> insert into DemoTable values('2010-01-10 12:30:45');
Query OK, 1 row affected (0.71 sec)
mysql> insert into DemoTable values('2010-01-12 12:30:45');
Query OK, 1 row affected (1.22 sec)
mysql> insert into DemoTable values('2010-01-20 12:30:45');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values('2010-01-20 12:30:45');
Query OK, 1 row affected (0.51 sec)
使用select语句显示表中的所有记录 –
mysql> select *from DemoTable;
将产生以下输出 –
+---------------------+
| AdmissionDate |
+---------------------+
| 2010-01-10 12:30:45 |
| 2010-01-10 12:30:45 |
| 2010-01-10 12:30:45 |
| 2010-01-12 12:30:45 |
| 2010-01-20 12:30:45 |
| 2010-01-20 12:30:45 |
+---------------------+
6 rows in set (0.00 sec)
以下是显示不同日期的查询 –
mysql> select distinct AdmissionDate from DemoTable;
将产生以下输出 –
+---------------------+
| AdmissionDate |
+---------------------+
| 2010-01-10 12:30:45 |
| 2010-01-12 12:30:45 |
| 2010-01-20 12:30:45 |
+---------------------+
3 rows in set (0.00 sec)
阅读更多:MySQL 教程