프로그래머스/SQL

[Level 4][GROUP BY] 저자 별 카테고리 별 매출액 집계하기

김초송 2023. 1. 3. 16:44

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

 

<MySQL>

SELECT b.author_id, a.author_name, b.category, sum(b.price * s.sales) total_sales
from book b 
    join author a on b.author_id = a.author_id
    join book_sales s on b.book_id = s.book_id
where s.sales_date between '2022-01-01 00:00:00' and '2022-01-31 23:59:59'
group by author_name, category
order by b.author_id, b.category desc;

between 에서 초까지 쓰는건 데이터리안 강의보면서 배움