본문 바로가기
💻 하나씩 차곡차곡/프로그래머스 (SQL)

[JOIN/LEVEL4] 주문량이 많은 아이스크림들 조회하기(MySQL/Oracle)

by 뚜루리 2024. 11. 18.
728x90
320x100

MySQL

SELECT FLAVOR
FROM (SELECT  FLAVOR
            , SUM(TOTAL_ORDER) AS TOTAL_ORDER
        FROM ( SELECT * FROM FIRST_HALF UNION ALL SELECT * FROM JULY) A
        GROUP BY FLAVOR
        ORDER BY TOTAL_ORDER DESC
        LIMIT 3) B

 


 

Oracle

SELECT FLAVOR
FROM (SELECT A.FLAVOR
        , A.TOTAL_ORDER + B.TOTAL_ORDER AS TOTAL_ORDER
        FROM (SELECT FLAVOR
                 , SUM(TOTAL_ORDER) AS TOTAL_ORDER
            FROM FIRST_HALF
            GROUP BY FLAVOR) A, 
            (SELECT FLAVOR
                 , SUM(TOTAL_ORDER) AS TOTAL_ORDER
            FROM JULY
            GROUP BY FLAVOR) B
        WHERE A.FLAVOR = B.FLAVOR
        ORDER BY TOTAL_ORDER DESC
      )
WHERE ROWNUM < 4
;
728x90
320x100