| SQL | 엑셀 |
|---|---|
| 데이터베이스 | 파일 |
| 테이블 | 시트 |
| 컬럼/필드 | 열 |
| 레코드 | 행 |
SQL 기초
Create Database Bootcamp;Create Table Data(
id INT,
name VARCHAR(50)
age INT
mbti VARCHAR(4)
);Insert INTO DATA (id, name, age, mbti) values (1, 'Junichi', 28, 'ENFJ');Select * from Data where age < 30 and mbti = 'ENFJ' order by id asc limit 5;Update Data set mbti = 'ENFP' where id = 1;Delete from Data where id = 1;집계 함수
Select Count(*) from Data;Select sum(age) from Data;조건문
Select name from Data where age = 28 and mbti = 'ENFP';Select Mbti from Data Where NOT Age < 30;기본키 Vs 외래키
Create Table Backend (
id INT Primary Key,
Sparta_id INT,
Foreign Key (Sparta_id) REFERENCES Sparta(id)
);해석 : Backend 라는 테이블 생성. 테이블 내 컬럼은 두 개
Select 문제

create table sparta_employees(
id INT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
position VARCHAR(30) NOT NULL,
salary int,
hire_date date
);
INSERT into 'sparta_employees' (`id`, `name`, `position`, `salary`, `hire_date`) VALUES ('1', '르탄이', '개발자', '30000', '2022-05-01');
INSERT into 'sparta_employees' (`id`, `name`, `position`, `salary`, `hire_date`) VALUES ('2', '배캠이', 'PM', '40000', '2021-09-25');
INSERT into 'sparta_employees' (`id`, `name`, `position`, `salary`, `hire_date`) VALUES ('3', '구구이', '파트장', '35000', '2023-06-01');
INSERT into 'sparta_employees' (`id`, `name`, `position`, `salary`, `hire_date`) VALUES ('4', '이션이', '팀장', '50000', '2021-07-09');
select * from sparta_employees;
select name, position from sparta_employees;
select DISTINCT position from sparta_employees;
select * from sparta_employees where salary BETWEEN 40000 and 60000;
select * from sparta_employees where hire_date < '2023-01-01';
사용법 : Distinct 컬럼
Select DISTINCT position from sparta_employees;
사용법 : Between N1 and N2
select * from sparta_employees where salary BETWEEN 40000 and 60000;