먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable1946 ( ShippingDate date ); Query OK, 0 rows affected (0.00 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable1946 values('2019-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2018-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2017-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2019-04-22'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2019-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2015-12-11'); Query OK, 1 row affected (0.00 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable1946;
이것은 다음과 같은 출력을 생성합니다 -
+--------------+ | ShippingDate | +--------------+ | 2019-12-11 | | 2018-12-11 | | 2017-12-11 | | 2019-04-22 | | 2019-12-11 | | 2015-12-11 | +--------------+ 6 rows in set (0.00 sec)
다음은 특정 날짜를 계산하는 쿼리입니다 -
mysql> select count(*) from DemoTable1946 where date(ShippingDate)='2019-12-11';
이것은 다음과 같은 출력을 생성합니다 -
+----------+ | count(*) | +----------+ | 2 | +----------+ 1 row in set (0.00 sec)