SELECT b.author_id,b.author_name,a.category,sum(a.price*c.sales) TOTAL_SALES
from book a
join author b
on a.author_id = b.author_id
join book_sales c
on a.book_id = c.book_id
where date_format(c.sales_date,'%Y-%m') = '2022-01'
group by 1,3
order by 1 asc,3 desc
SELECT b.author_id,b.author_name,a.category,a.price*sum(c.sales) TOTAL_SALES
from book a
join author b
on a.author_id = b.author_id
join book_sales c
on a.book_id = c.book_id
where date_format(c.sales_date,'%Y-%m') = '2022-01'
group by 1,3
order by 1 asc,3 desc
a.price*sum(c.sales) TOTAL_SALES
이 부분때문에 계속 에러가 났다.
예를 들어 이 예제 데이터에서, a.price*sum(c.sales) TOTAL_SALES
로 작성하면 1000*8 인지 2000*8인지 알 수 없다.
따라서 sum(a.price*c.sales) TOTAL_SALES
처럼 SUM을 전체에 묶어줘야 한다.