먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeSalary int ); Query OK, 0 rows affected (1.68 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable(EmployeeSalary) values(12000); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(EmployeeSalary) values(20000); Query OK, 1 row affected (0.55 sec) mysql> insert into DemoTable(EmployeeSalary) values(11500); Query OK, 1 row affected (0.94 sec) mysql> insert into DemoTable(EmployeeSalary) values(15500); Query OK, 1 row affected (0.44 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable;
이것은 다음과 같은 출력을 생성합니다 -
+----+----------------+ | Id | EmployeeSalary | +----+----------------+ | 1 | 12000 | | 2 | 20000 | | 3 | 11500 | | 4 | 15500 | +----+----------------+ 4 rows in set (0.00 sec)
다음은 IF 문의 결과로 문자열을 반환하는 쿼리입니다 -
mysql> select Id,if(EmployeeSalary <= 12000 ,'Internship Employee','FullTime Employee') as status from DemoTable;
이것은 다음과 같은 출력을 생성합니다 -
+----+---------------------+ | Id | status | +----+---------------------+ | 1 | Internship Employee | | 2 | FullTime Employee | | 3 | Internship Employee | | 4 | FullTime Employee | +----+---------------------+ 4 rows in set (0.00 sec)