team_projects(ํ๋ก์ ํธ) ํ
์ด๋ธ
id | name | start_date | end_date | aws_cost |
---|
1 | ์ผ์กฐ | 2023-01-01 | 2023-01-07 | 30000 |
2 | ๊ฟ๊พธ๋์ด์กฐ | 2023-03-15 | 2023-03-22 | 50000 |
3 | ๋ณด๋์ผ์กฐ | 2023-11-20 | 2023-11-30 | 80000 |
4 | ์ฌ์กฐ์ฐธ์น | 2022-07-01 | 2022-07-30 | 75000 |
ํ
์ด๋ธ ์์ฑ, ๋ฐ์ดํฐ ์ฝ์
์ฟผ๋ฆฌ
create table team_projects
(
id int unsigned,
name varchar(10),
start_date date,
end_date date,
aws_cost int unsigned
);
insert into team_projects(id, name, start_date, end_date, aws_cost)values
(1, "์ผ์กฐ", "2023-01-01", "2023-01-07", 30000),
(2, "๊ฟ๊พธ๋์ด์กฐ", "2023-03-15", "2023-03-22", 50000),
(3, "๋ณด๋์ผ์กฐ", "2023-11-20", "2023-11-30", 80000),
(4, "์ฌ์กฐ์ฐธ์น", "2022-07-01", "2022-07-30", 75000);
์ฐ์ต๋ฌธ์
team_projects
ํ
์ด๋ธ์์ AWS ์์ฐ(aws_cost)์ด 40000 ์ด์ ๋ค์ด๊ฐ ํ๋ก์ ํธ๋ค์ ์ด๋ฆ์ ์ ํํ๋ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ์ธ์!
select name
from team_projects
where aws_cost >= 40000;
team_projects
ํ
์ด๋ธ์์ 2022๋
์ ์์๋ ํ๋ก์ ํธ๋ฅผ ์ ํํ๋ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ์ธ์! ๋จ, start_date < โ2023-01-01โ ์กฐ๊ฑด์ ์ฌ์ฉํ์ง ๋ง๊ณ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ์ธ์!
select *
from team_projects
where start_date like "2022%";
team_projects
ํ
์ด๋ธ์์ ํ์ฌ ์งํ์ค์ธ ํ๋ก์ ํธ๋ฅผ ์ ํํ๋ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ์ธ์. ๋จ, ์ง๊ธ ์์ ์ ๋ ์ง๋ฅผ ํ๋์ฝ๋ฉํด์ ์ฟผ๋ฆฌํ์ง ๋ง์์ฃผ์ธ์!
select *
from team_projects
where curdate() between start_date and end_date;
team_projects
ํ
์ด๋ธ์์ ๊ฐ ํ๋ก์ ํธ์ ์ง์ ๊ธฐ๊ฐ์ ์ผ ์๋ก ๊ณ์ฐํ๋ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํด์ฃผ์ธ์!
select id, name, start_date, end_date, aws_cost,
datediff(end_date, start_date) as "ํ๋ก์ ํธ ์ง์๊ธฐ๊ฐ"
from team_projects;