먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable732 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, PassengerId int, PassengerName varchar(100), PassengerAge int, PassengerTravelDatetime datetime ); Query OK, 0 rows affected (0.67 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable732(PassengerId,PassengerName,PassengerAge,PassengerTravelDatetime) values(110,'Chris',25,'2019-07-23 12:45:56'); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable732(PassengerId,PassengerName,PassengerAge,PassengerTravelDatetime) values(120,'Robert',24,'2019-07-21 11:05:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable732(PassengerId,PassengerName,PassengerAge,PassengerTravelDatetime) values(120,'Sam',26,'2019-07-21 11:05:00'); Query OK, 1 row affected (0.30 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable732;
그러면 다음과 같은 출력이 생성됩니다. -
+----+-------------+---------------+--------------+-------------------------+ | Id | PassengerId | PassengerName | PassengerAge | PassengerTravelDatetime | +----+-------------+---------------+--------------+-------------------------+ | 1 | 110 | Chris | 25 | 2019-07-23 12:45:56 | | 2 | 120 | Robert | 24 | 2019-07-21 11:05:00 | | 3 | 120 | Sam | 26 | 2019-07-21 11:05:00 | +----+-------------+---------------+--------------+-------------------------+ 3 rows in set (0.00 sec)
다음은 간단한 SELECT COUNT SQL 쿼리 오류에 대한 쿼리입니다. -
mysql> select count(Id) from DemoTable732 where PassengerId=120 and date(PassengerTravelDatetime)='2019-07-21';
그러면 다음과 같은 출력이 생성됩니다. -
+-----------+ | count(Id) | +-----------+ | 2 | +-----------+ 1 row in set (0.00 sec)