먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable1496 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> PassengerCode varchar(20), -> ArrivalDate datetime -> ); Query OK, 0 rows affected (0.85 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable1496(PassengerCode,ArrivalDate) values('202','2013-03-12 10:12:34'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1496(PassengerCode,ArrivalDate) values('202_John','2013-03-12 11:00:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1496(PassengerCode,ArrivalDate) values('204','2013-03-12 10:12:34'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1496(PassengerCode,ArrivalDate) values('208','2013-03-14 11:10:00'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1496(PassengerCode,ArrivalDate) values('202','2013-03-18 12:00:34'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1496(PassengerCode,ArrivalDate) values('202','2013-03-18 04:10:01'); Query OK, 1 row affected (0.15 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable1496;
이것은 다음과 같은 출력을 생성합니다 -
+----+---------------+---------------------+ | Id | PassengerCode | ArrivalDate | +----+---------------+---------------------+ | 1 | 202 | 2013-03-12 10:12:34 | | 2 | 202_John | 2013-03-12 11:00:00 | | 3 | 204 | 2013-03-12 10:12:34 | | 4 | 208 | 2013-03-14 11:10:00 | | 5 | 202 | 2013-03-18 12:00:34 | | 6 | 202 | 2013-03-18 04:10:01 | +----+---------------+---------------------+ 6 rows in set (0.00 sec)
다음은 날짜별로 결과를 그룹화하고 중복 값의 개수를 표시하는 쿼리입니다 -
mysql> select date(ArrivalDate),count(ArrivalDate) from DemoTable1496 -> where PassengerCode like concat('%','202','%') -> group by date(ArrivalDate);
이것은 다음과 같은 출력을 생성합니다 -
+-------------------+--------------------+ | date(ArrivalDate) | count(ArrivalDate) | +-------------------+--------------------+ | 2013-03-12 | 2 | | 2013-03-18 | 2 | +-------------------+--------------------+ 2 rows in set (0.00 sec)