[Programmers] SQL - 저자 별 카테고리 별 매출액 집계하기

DMIS·2023년 1월 2일
0

SQL

목록 보기
44/48
post-thumbnail

문제

풀이

조인 열심히 하고, 문제 중간에 1월에 대한 판매량만 계산해달라고 했으므로 where 절에 조건을 추가해주면 된다.

select 
    t1.author_id,
    t2.author_name,
    t1.category,
    sum(sales*price) as total_sales
from book t1
left join author t2
on t1.author_id = t2.author_id
left join book_sales t3
on t1.book_id = t3.book_id
where sales_date between '2022-01-01' and '2022-01-31'
group by 1, 2, 3
order by author_id, category desc;
profile
Data + Math

0개의 댓글