본문 바로가기
프로그래머스/[프로그래머스 - ORACLE] Lv.4

[프로그래머스 - ORACLE] 주문량이 많은 아이스크림들 조회하기

by 코딩하는 흰둥이 2023. 3. 23.


CREATE 문
CREATE TABLE FIRST_HALF (
SHIPMENT_ID		NUMBER 		NOT NULL,
FLAVOR			VARCHAR(20)	NOT NULL,
TOTAL_ORDER		NUMBER 		NOT NULL
)


CREATE TABLE JULY     (
SHIPMENT_ID		NUMBER			NOT NULL,
FLAVOR			VARCHAR(20)		NOT NULL,
TOTAL_ORDER		NUMBER			NOT NULL,
CONSTRAINT FK_SHIPMENT_ID FOREIGN KEY(SHIPMENT_ID) REFERENCES FIRST_HALF(SHIPMENT_ID)
)

  • 내 풀이
-- 코드를 입력하세요
SELECT
    FLAVOR
FROM(
    SELECT
        H.FLAVOR,
        SUM(H.TOTAL_ORDER + J.TOTAL_ORDER) AS TOTAL
    FROM FIRST_HALF H INNER JOIN JULY J
    ON H.FLAVOR = J.FLAVOR
    GROUP BY H.FLAVOR
    ORDER BY TOTAL DESC
    )
    WHERE ROWNUM <= 3;

 

댓글