먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(40), StudentMathMarks int, StudentMySQLMarks int, status ENUM('ACTIVE','INACTIVE') ); Query OK, 0 rows affected (0.47 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable(StudentName,StudentMathMarks,StudentMySQLMarks,status) values('Chris',45,67,'active'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(StudentName,StudentMathMarks,StudentMySQLMarks,status) values('Bob',89,78,'inactive'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(StudentName,StudentMathMarks,StudentMySQLMarks,status) values('David',56,68,'active'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName,StudentMathMarks,StudentMySQLMarks,status) values('Robert',68,75,'active'); Query OK, 1 row affected (0.18 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable;
이것은 다음과 같은 출력을 생성합니다 -
+-----------+-------------+------------------+-------------------+----------+ | StudentId | StudentName | StudentMathMarks | StudentMySQLMarks | status | +-----------+-------------+------------------+-------------------+----------+ | 1 | Chris | 45 | 67 | ACTIVE | | 2 | Bob | 89 | 78 | INACTIVE | | 3 | David | 56 | 68 | ACTIVE | | 4 | Robert | 68 | 75 | ACTIVE | +-----------+-------------+------------------+-------------------+----------+ 4 rows in set (0.00 sec)
다음은 AND &OR 연산자 -
를 사용하여 여러 행 레코드를 반환하는 쿼리입니다.mysql> select *from DemoTable where status='active' and (StudentMathMarks=68 or StudentMySQLMarks=67);
이것은 다음과 같은 출력을 생성합니다 -
+-----------+-------------+------------------+-------------------+--------+ | StudentId | StudentName | StudentMathMarks | StudentMySQLMarks | status | +-----------+-------------+------------------+-------------------+--------+ | 1 | Chris | 45 | 67 | ACTIVE | | 4 | Robert | 68 | 75 | ACTIVE | +-----------+-------------+------------------+-------------------+--------+ 2 rows in set (0.00 sec)