https://school.programmers.co.kr/learn/courses/30/lessons/144856

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

풀이

 

1. author 테이블과 book 테이블 inner join

book_id, author_id, category, author_name, book.price 정보를 담은 테이블 출력

 

2. 1번 테이블과 book_sales 테이블 inner join 

 

3. 작가번호, 이름, 카테고리로 그룹화 후 price * sales 집계

 

select distinct a.author_id, a.author_name, category, sum(price*sales) as total_sales
from 
(
select book_id, author.author_id, category, author_name, book.price
from book inner join author
on book.author_id = author.author_id
) as a inner join book_sales as b
on a.book_id = b.book_id
where date_format(b.sales_date,'%Y-%m') = '2022-01'
group by author_id, author_name, category
order by a.author_id, category desc

+ Recent posts