월별로 선택하려면 MONTH() 함수를 사용하십시오. 먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable1599 -> ( -> Shippingdate datetime -> ); Query OK, 0 rows affected (0.78 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable1599 values('2019-10-21'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1599 values('2018-12-12'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable1599 values('2015-11-21'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1599 values('2017-12-31'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1599 values('2018-12-26'); Query OK, 1 row affected (0.17 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable1599;
이것은 다음과 같은 출력을 생성합니다 -
+---------------------+ | Shippingdate | +---------------------+ | 2019-10-21 00:00:00 | | 2018-12-12 00:00:00 | | 2015-11-21 00:00:00 | | 2017-12-31 00:00:00 | | 2018-12-26 00:00:00 | +---------------------+ 5 rows in set (0.00 sec)
다음은 월별 SELECT 쿼리입니다 -
mysql> select * from DemoTable1599 -> where month(Shippingdate)=12;
이것은 다음과 같은 출력을 생성합니다 -
+---------------------+ | Shippingdate | +---------------------+ | 2018-12-12 00:00:00 | | 2017-12-31 00:00:00 | | 2018-12-26 00:00:00 | +---------------------+ 3 rows in set (0.00 sec)