저자 별 카테고리 별 매출액 집계하기
https://school.programmers.co.kr/learn/courses/30/lessons/144856
- 문제 풀이
1
2
3
4
5
6
7
8
9
SELECT A.AUTHOR_ID, A.AUTHOR_NAME, B.CATEGORY, SUM(B.PRICE * S.SALES) AS "TOTAL_SALES"
FROM BOOK B
JOIN BOOK_SALES S
ON B.BOOK_ID = S.BOOK_ID
JOIN AUTHOR A
ON B.AUTHOR_ID = A.AUTHOR_ID
WHERE TO_CHAR(SALES_DATE, 'YYYY-MM') = '2022-01'
GROUP BY A.AUTHOR_ID, A.AUTHOR_NAME, B.CATEGORY
ORDER BY A.AUTHOR_ID, B.CATEGORY DESC;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
SELECT
B.AUTHOR_ID,
B.AUTHOR_NAME,
A.CATEGORY,
SUM(A.PRICE * C.SALES) AS "TOTAL_SALES"
FROM
BOOK A,
AUTHOR B,
BOOK_SALES C
WHERE
TO_CHAR(C.SALES_DATE, 'YYYYMM') = '202201'
AND A.AUTHOR_ID = B.AUTHOR_ID
AND A.BOOK_ID = C.BOOK_ID
GROUP BY
B.AUTHOR_ID,
B.AUTHOR_NAME,
A.CATEGORY
ORDER BY
B.AUTHOR_ID,
A.CATEGORY DESC;
- 실행 결과
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.