๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • Welcome.
:: DBMS ๐Ÿšฉ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค SQL ๊ณ ๋“์  kit ํ’€์ด

JOIN>์ฃผ๋ฌธ๋Ÿ‰์ด ๋งŽ์€ ์•„์ด์Šคํฌ๋ฆผ๋“ค ์กฐํšŒํ•˜๊ธฐ

by EunBird 2023. 2. 26.
-- ์ง์ ‘ ์ง  ์ฝ”๋“œ.
SELECT C.FLAVOR FROM
    (
    SELECT A.SHIPMENT_ID, A.FLAVOR, SUM(A.TOTAL_ORDER + B.TOTAL_ORDER) AS TOTAL
    FROM FIRST_HALF A
    JOIN JULY B ON A.FLAVOR = B.FLAVOR
    GROUP BY FLAVOR
    ORDER BY TOTAL DESC
    ) AS C
ORDER BY C.TOTAL DESC
LIMIT 3

-- GPT๋กœ๋ถ€ํ„ฐ  ์ฒจ์‚ญ๋ฐ›์Œ.
SELECT C.FLAVOR FROM
    (
    SELECT A.FLAVOR, SUM(A.TOTAL_ORDER + B.TOTAL_ORDER) AS TOTAL
    FROM FIRST_HALF A
    JOIN JULY B ON A.FLAVOR = B.FLAVOR
    GROUP BY FLAVOR
    ) AS C
ORDER BY C.TOTAL DESC
LIMIT 3
-- ์ธํ„ฐ๋„ท์—์„œ ์ฐพ์€ ๋ฐฉ๋ฒ•. 
SELECT A.FLAVOR
FROM FIRST_HALF A
JOIN  
    (
    SELECT FLAVOR, SUM(TOTAL_ORDER) AS  TOTAL_ORDER
    FROM JULY
    GROUP BY FLAVOR
    ) AS B
ON A.FLAVOR = B.FLAVOR
ORDER BY A.TOTAL_ORDER + B.TOTAL_ORDER DESC
LIMIT 3
728x90

๋Œ“๊ธ€