sparta_employees(์ง์) ํ
์ด๋ธ
id | name | position | salary | hire_date |
---|
1 | ๋ฅดํ์ด | ๊ฐ๋ฐ์ | 30000 | 2022-05-01 |
2 | ๋ฐฐ์บ ์ด | PM | 40000 | 2021-09-25 |
3 | ๊ตฌ๊ตฌ์ด | ํํธ์ฅ | 35000 | 2023-06-01 |
4 | ์ด์ ์ด | ํ์ฅ | 50000 | 2021-07-09 |
ํ
์ด๋ธ ์์ฑ, ๋ฐ์ดํฐ ์ฝ์
์ฟผ๋ฆฌ
create table sparta_employees
(
id int,
name varchar(10),
position varchar(10),
salary int,
hire_date date
);
insert into sparta_employees(id, name, position, salary, hire_date) values
(1, "๋ฅดํ์ด", "๊ฐ๋ฐ์", 30000, "2022-05-01"),
(2, "๋ฐฐ์บ ์ด", "PM", 40000, "2021-09-25"),
(3, "๊ตฌ๊ตฌ์ด", "ํํธ์ฅ", 35000, "2023-06-01"),
(4, "์ด์
์ด", "ํ์ฅ", 50000, "2021-07-09");
์ฐ์ต ๋ฌธ์
sparta_employees
ํ
์ด๋ธ์์ ๋ชจ๋ ์ง์์ ์ด๋ฆ(name)๊ณผ ์ง๊ธ(position)์ ์ ํํ๋ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ์ธ์.
select name, position
from sparta_employees;
sparta_employees
ํ
์ด๋ธ์์ ์ค๋ณต ์์ด ๋ชจ๋ ์ง๊ธ(position)์ ์ ํํ๋ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ์ธ์.
select distinct position
from sparta_employees;
sparta_employees
ํ
์ด๋ธ์์ ์ฐ๋ด(salary)์ด 40000๊ณผ 60000 ์ฌ์ด์ธ ์ง์๋ค์ ์ ํํ๋ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ์ธ์.
select *
from sparta_employees
where salary between 40000 and 60000;
sparta_employees
ํ
์ด๋ธ์์ ์
์ฌ์ผ(hire_date)์ด 2023๋
1์ 1์ผ ์ด์ ์ธ ๋ชจ๋ ์ง์๋ค์ ์ ํํ๋ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ์ธ์.
select *
from sparta_employees
where hire_date < "2023-01-01";