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
'코딩테스트 > 문제풀이' 카테고리의 다른 글
[프로그래머스] 특정 기간동안 대여 가능한 자동차들의 대여비용 구하기 SQL (0) | 2023.10.03 |
---|---|
[프로그래머스] 가격대 별 상품 개수 구하기 SQL (0) | 2023.10.03 |
[프로그래머스] 자동차 대여 기록 별 대여 금액 구하기 SQL (0) | 2023.10.03 |
[프로그래머스] 입양 시각 구하기(2) SQL (1) | 2023.10.02 |
[프로그래머스] 년, 월, 성별 별 상품 구매 회원 수 구하기 SQL (0) | 2023.10.01 |