MySQL Workbench를 사용하여 강의 내용을 복습한다.
passenger
테이블을 생성하고 자유롭게 데이터를 추가한다.plane
테이블을 생성하고 자유롭게 데이터를 추가한다.assignment
스키마 생성CREATE SCHEMA 'assignment';
passenger
테이블 생성CREATE TABLE `assignment`.`passenger` (
`passenger_id` INT NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR(30) NOT NULL,
`first_name` VARCHAR(30) NOT NULL,
`nationality` VARCHAR(30) NOT NULL,
`plane` INT NOT NULL,
PRIMARY KEY(`passenger_id`));
plane
테이블 생성CREATE TABLE `assignment`.`plane` (
`plane_id` INT NOT NULL AUTO_INCREMENT,
`departure` VARCHAR(45) NOT NULL,
`arrival` VARCHAR(45) NOT NULL,
`departure_time` DATETIME NOT NULL,
`gate` INT NOT NULL,
`meal` TINYINT NOT NULL,
PRIMARY KEY(`plane_id`));
passenger
테이블에 데이터 추가INSERT INTO `assignment`.`passenger` (`passenger_id`, `last_name`, `first_name`, `nationality`, `plane`) VALUES ('1', '김', '예지', '한국', '1');
INSERT INTO `assignment`.`passenger` (`passenger_id`, `last_name`, `first_name`, `nationality`, `plane`) VALUES ('2', 'Smith', 'Oliver', '호주', '4');
INSERT INTO `assignment`.`passenger` (`passenger_id`, `last_name`, `first_name`, `nationality`, `plane`) VALUES ('3', '김', '태연', '한국', '3');
INSERT INTO `assignment`.`passenger` (`passenger_id`, `last_name`, `first_name`, `nationality`, `plane`) VALUES ('4', '후지오카', '하루히', '일본', '1');
INSERT INTO `assignment`.`passenger` (`passenger_id`, `last_name`, `first_name`, `nationality`, `plane`) VALUES ('5', '예', '슈화', '대만', '2');
INSERT INTO `assignment`.`passenger` (`passenger_id`, `last_name`, `first_name`, `nationality`, `plane`) VALUES ('6', '송', '몽숙', '한국', '1');
INSERT INTO `assignment`.`passenger` (`passenger_id`, `last_name`, `first_name`, `nationality`, `plane`) VALUES ('7', 'Williams', 'Noah', '영국', '3');
INSERT INTO `assignment`.`passenger` (`passenger_id`, `last_name`, `first_name`, `nationality`, `plane`) VALUES ('8', 'Taylor', 'Swift', '미국', '5');
plane
테이블에 데이터 추가INSERT INTO `assignment`.`plane` (`departure`, `arrival`, `departure_time`, `gate`, `meal`) VALUES ('서울', '로마', '2023-03-30 12:10:00', '57', '1');
INSERT INTO `assignment`.`plane` (`departure`, `arrival`, `departure_time`, `gate`, `meal`) VALUES ('서울', '오사카', '2023-04-14 09:35:00', '9', '0');
INSERT INTO `assignment`.`plane` (`departure`, `arrival`, `departure_time`, `gate`, `meal`) VALUES ('런던', '파리', '2023-07-02 19:00:00', '26', '0');
INSERT INTO `assignment`.`plane` (`departure`, `arrival`, `departure_time`, `gate`, `meal`) VALUES ('시드니', '뉴욕', '2023-12-24 14:55:00', '144', '1');
INSERT INTO `assignment`.`plane` (`departure`, `arrival`, `departure_time`, `gate`, `meal`) VALUES ('뉴욕', '서울', '2024-01-15 13:20:00', '97', '1');
SELECT passenger_id,last_name,first_name,nationality,departure,arrival,departure_time,gate,meal FROM passenger LEFT JOIN plane ON plane = plane_id;
이 부분
이런식으로 한번에 넣을 수 있어요^^