카테고리 별 도서 판매량 집계하기
https://school.programmers.co.kr/learn/courses/30/lessons/144855
- 문제 풀이
1
2
3
4
5
6
7
8
9
10
11
12
SELECT
B.CATEGORY,
SUM(S.SALES) AS "TOTAL_SALES"
FROM
BOOK_SALES S, BOOK B
WHERE
B.BOOK_ID = S.BOOK_ID
AND SALES_DATE BETWEEN TO_DATE(20220101, 'YYYY-MM-DD') AND TO_DATE(20220131, 'YYYY-MM-DD')
GROUP BY
B.CATEGORY
ORDER BY
B.CATEGORY;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SELECT
B.CATEGORY,
SUM(S.SALES) AS "TOTAL_SALES"
FROM
BOOK B
JOIN
BOOK_SALES S
ON
B.BOOK_ID = S.BOOK_ID
WHERE
TO_CHAR(S.SALES_DATE, 'YYYY-MM') = '2022-01'
GROUP BY
B.CATEGORY
ORDER BY
B.CATEGORY;
1
2
3
4
5
6
7
8
9
10
11
12
13
SELECT
B.CATEGORY,
SUM(SALES) AS "TOTAL_SALES"
FROM
BOOK B
JOIN
(SELECT * FROM BOOK_SALES WHERE TO_CHAR(SALES_DATE, 'YYYY-MM') = '2022-01') S
ON
B.BOOK_ID = S.BOOK_ID
GROUP BY
B.CATEGORY
ORDER BY
B.CATEGORY;
- 실행 결과
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.