๋ฐ์ํ
https://school.programmers.co.kr/learn/courses/30/lessons/144856
2022๋ 1์์ ๋์ ํ๋งค ๋ฐ์ดํฐ๋ฅผ ๊ธฐ์ค์ผ๋ก
์ ์ ๋ณ, ์นดํ ๊ณ ๋ฆฌ ๋ณ
๋งค์ถ์ก(TOTAL_SALES = ํ๋งค๋ * ํ๋งค๊ฐ) ์ ๊ตฌํ์ฌ,
์ ์ ID(AUTHOR_ID), ์ ์๋ช
(AUTHOR_NAME), ์นดํ
๊ณ ๋ฆฌ(CATEGORY), ๋งค์ถ์ก(SALES) ๋ฆฌ์คํธ๋ฅผ ์ถ๋ ฅํ๋ SQL๋ฌธ์ ์์ฑํด์ฃผ์ธ์.
๊ฒฐ๊ณผ๋ ์ ์ ID๋ฅผ ์ค๋ฆ์ฐจ์์ผ๋ก, ์ ์ ID๊ฐ ๊ฐ๋ค๋ฉด ์นดํ
๊ณ ๋ฆฌ๋ฅผ ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌํด์ฃผ์ธ์.
select b.author_id, a.author_name, b.category, sum(s.sales*b.price) as total_sales
from book b
join author a on b.author_id = a.author_id
join book_sales s on s.book_id = b.book_id
where date_format(s.sales_date, "%Y%m") = '202201'
group by b.author_id, b.category
order by b.author_id asc, b.category desc
๋ฐ์ํ