31๋ฒ
https://school.programmers.co.kr/learn/courses/30/lessons/59044
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
32๋ฒ
https://school.programmers.co.kr/learn/courses/30/lessons/144855
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
with cte_book as (
select book_id,
category
from BOOK
)
select category,
sum(sales) as total_sales
from BOOK_SALES
inner join cte_book
on BOOK_SALES.book_id = cte_book.book_id
where year(sales_date) = 2022 and month(sales_date) = 1
group by category
order by category
33๋ฒโ๏ธโ๏ธ
https://school.programmers.co.kr/learn/courses/30/lessons/131533
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
select product_code,
sum(sales_amount) * price as sales
from OFFLINE_SALE s
inner join product p
on s.product_id = p.product_id
group by product_code
order by sales desc, product_code
group by product_code ์ฌ์ฉํ
select ๋ฌธ์์ sum(sales_amount) * price
price๋ง ์ฌ์ฉํด๋ ํด๋น product_code์ ๋ง๋ price๊ฐ ์ถ๋ ฅ๋๋ค
34๋ฒ
https://school.programmers.co.kr/learn/courses/30/lessons/59043
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
select a_in.animal_id,
a_in.name
from ANIMAL_INS a_in
inner join ANIMAL_OUTS a_out
on a_in.animal_id = a_out.animal_id
and a_in.datetime > a_out.datetime
order by a_in.datetime
35๋ฒ
https://school.programmers.co.kr/learn/courses/30/lessons/59411
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
select i.animal_id,
i.name
from ANIMAL_INS i
inner join ANIMAL_OUTS o
on i.animal_id = o.animal_id
order by (o.datetime - i.datetime) desc
limit 2
36๋ฒ
https://school.programmers.co.kr/learn/courses/30/lessons/59045
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
select i.animal_id,
i.animal_type,
i.name
from ANIMAL_INS i
inner join ANIMAL_OUTS o
on i.animal_id = o.animal_id
where i.SEX_UPON_INTAKE like '%Intact%'
and (o.SEX_UPON_OUTCOME like '%Spayed%' or o.SEX_UPON_OUTCOME like '%Neutered%')
order by i.animal_id
37๋ฒ
https://school.programmers.co.kr/learn/courses/30/lessons/144854
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
select b.book_id,
a.author_name,
date_format(b.published_date, '%Y-%m-%d') as published_date
from BOOK b
inner join AUTHOR a
on b.author_id = a.author_id
where b.category = '๊ฒฝ์ '
order by date_format(b.published_date, '%Y-%m-%d')
38๋ฒ
https://school.programmers.co.kr/learn/courses/30/lessons/131113
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
SELECT order_id,
product_id,
date_format(out_date, '%Y-%m-%d') as out_date,
case when date_format(out_date, '%Y-%m-%d') <= '2022-05-01' then '์ถ๊ณ ์๋ฃ'
when date_format(out_date, '%Y-%m-%d') > '2022-05-01' then '์ถ๊ณ ๋๊ธฐ'
else '์ถ๊ณ ๋ฏธ์ ' end as '์ถ๊ณ ์ฌ๋ถ'
from FOOD_ORDER