CRUD 및 문자열 처리 실습
● test5 데이터베이스에 employees 테이블 생성
Table Name : employees
- id : 직원 고유 ID (프라이머리 키, 자동증가)
- name : 직원명 (문자열, 최대 50자)
- position : 직급 (문자열, 최대 50자)
- email : 이메일 (문자열, 최대 100자)
- phone_number : 전화번호 (문자열, 최대 15자)
- salary : 급여 (정수형)

● employees 테이블에 데이터 추가
|
INSERT INTO employees (name, position, email, phone_number, salary) VALUES
('김철수', 'Manager', 'chulsoo.kim@example.com', '010-1234-5678', 5000000), ('이영희', 'Developer', 'younghee.lee@example.com', '010-2345-6789', 4000000), ('박준혁', 'Designer', 'junhyuk.park@example.com', '010-3456-7890', 3500000), ('최수진', 'Tester', 'sujin.choi@example.com', '010-4567-8901', 3200000), ('정우진', 'HR', 'woojin.jung@example.com', '010-5678-9012', 3000000); |
● 실습문제
1. 신규 직원 '한지수'를 다음 정보를 사용하여 추가.
직위 : Developer
이메일 : jisu.han@example.com
전화번호 : 010-6789-0123
연봉 : 3800000
|
insert into employees(name, position, email, phone_number, salary)
values ('한지수', 'Developer', 'jisu.han@example.com', '010-6789-0123', 3800000); |

2. 모든 직원의 이름과 이메일을 조회하되, 전화번호는 가운데 숫자를 마스킹(*) 처리하여 출력.
|
select name, email, replace(phone_number, substr(phone_number, 5, 4), '****') as phone_number
from employees; |

3. 연봉 350만 원 이상인 직원의 이름과 직위를 조회.
|
select name, position
from employees where salary >= 3500000; |

4. '이영희'의 직위를 'Senior Developer'로 변경하고 연봉을 450만 원으로 업데이트.
|
update employees set position = 'Senior Developer', salary = 4500000 where name = '이영희'; |

5. 연봉이 300만 원 미만인 직원을 삭제.
|
delete
from employees where salary < 3000000; |
기존에 있던 데이터에 연봉이 300만원 미만인 직원은 없다.
그렇기 때문에 위 쿼리를 실행하면 오류는 뜨지 않지만 정상으로 실행되고 변경된 값이 없다고 나온다.

6. 직원의 이름과 직위를 하나의 문자열로 결합하여 출력. (예: '김철수 - Manager')
|
select concat(name, ' - ' ,position) as info from employees; |

7. 직원의 이름 중 두 번째 글자부터 세 번째 글자까지 출력.
|
select substr(name,2, 2) name from employees; |

8. 각 직원의 이메일 길이를 계산하여 출력.
|
select char_length(email) email_length from employees; |


'Database > MySQL 실습' 카테고리의 다른 글
| [DBeaver] MySQL 실습 - 시간처리 실습 (2) | 2025.02.02 |
|---|---|
| [DBeaver] MySQL 실습 - 키워드를 이용해 특수한 컬럼 조회하기 : group by, having (0) | 2025.01.28 |
| [DBeaver] MySQL 실습 - CRUD 및 문자열 처리 실습 2 (0) | 2025.01.14 |
| [DBeaver] MySQL 실습 - CRUD 실습 (데이터 추가, 조회, 수정, 삭제) (2) | 2025.01.12 |
| [DBeaver] MySQL실습 - 문자열 처리 실습 (0) | 2025.01.12 |