먼저 테이블을 생성하겠습니다 -
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)