:: DBMS ๐ฉ/ํ๋ก๊ทธ๋๋จธ์ค SQL ๊ณ ๋์ kit ํ์ด13 JOIN>๋ณดํธ์์์ ์ค์ฑํํ ๋๋ฌผ -- ์๋ธ์ฟผ๋ฆฌ ์ฌ์ฉ SELECT A.ANIMAL_ID, A.ANIMAL_TYPE, A.NAME FROM ANIMAL_INS A JOIN ( SELECT ANIMAL_ID, ANIMAL_TYPE, NAME FROM ANIMAL_OUTS WHERE SEX_UPON_OUTCOME NOT LIKE 'Intact %' ) B ON A.ANIMAL_ID = B.ANIMAL_ID WHERE A.SEX_UPON_INTAKE LIKE 'Int%' ORDER BY A.ANIMAL_ID -- ์กฐ์ธ๋ง ์ฌ์ฉ. SELECT A.ANIMAL_ID, A.ANIMAL_TYPE, A.NAME FROM ANIMAL_INS A JOIN ANIMAL_OUTS B ON A.ANIMAL_ID = B.ANIMAL_ID WHERE A.SEX_UPO.. 2023. 2. 26. JOIN>5์ ์ํ๋ค์ ์ด๋งค์ถ ์กฐํํ๊ธฐ SELECT A.PRODUCT_ID, A.PRODUCT_NAME, **SUM**(B.AMOUNT*A.PRICE) AS TOTAL_SALES FROM FOOD_PRODUCT A JOIN FOOD_ORDER B ON A.PRODUCT_ID = B.PRODUCT_ID WHERE B.PRODUCE_DATE LIKE '2022-05-%' **GROUP BY PRODUCT_ID** ORDER BY TOTAL_SALES DESC, PRODUCT_ID 2023. 2. 26. JOIN>์ฃผ๋ฌธ๋์ด ๋ง์ ์์ด์คํฌ๋ฆผ๋ค ์กฐํํ๊ธฐ -- ์ง์ ์ง ์ฝ๋. 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.. 2023. 2. 26. JOIN>๊ทธ๋ฃน๋ณ ์กฐ๊ฑด์ ๋ง๋ ์๋น ๋ชฉ๋ก ์ถ๋ ฅํ๊ธฐ -- ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์ select member_name, review_text, review_date from member_profile A join rest_review B on A.member_id = B.member_id where member_name like ( select /*member_id,*/ rank() over (order by count(member_id)) as cnt from rest_review group by member_id order by cnt desc ) -- select * from rest_review select member_id, rank() over (order by count(*)) as cnt from rest_review group by member_i.. 2023. 2. 26. JOIN>์ค๋ ๊ธฐ๊ฐ ๋ณดํธํ ๋๋ฌผ(1) -- JOIN ๋ฏธ์ฌ์ฉ SELECT NAME, DATETIME FROM ANIMAL_INS WHERE ANIMAL_ID NOT IN (SELECT ANIMAL_ID FROM ANIMAL_OUTS) ORDER BY DATETIME LIMIT 3 --JOIN ์ฌ์ฉ SELECT A.NAME, A.DATETIME FROM ANIMAL_INS A LEFT JOIN ANIMAL_OUTS B ON A.ANIMAL_ID = B.ANIMAL_ID WHERE B.ANIMAL_ID IS NULL ORDER BY DATETIME LIMIT 3 2023. 2. 26. JOIN>์์๋๋ฐ์ ์์์ต๋๋ค -- ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์ SELECT B.ANIMAL_ID, B.NAME FROM ANIMAL_INS A JOIN ANIMAL_OUTS B ON A.ANIMAL_ID = B.ANIMAL_ID WHERE A.DATETIME > B.DATETIME ORDER BY A.DATETIME ; 2023. 2. 26. JOIN>์์ด์ง ๊ธฐ๋ก ์ฐพ๊ธฐ -- ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์ SELECT **DISTINCT**(B.ANIMAL_ID), B.NAME FROM ANIMAL_INS A **JOIN ANIMAL_OUTS B** **WHERE B.ANIMAL_ID NOT IN (SELECT ANIMAL_ID FROM ANIMAL_INS)** ORDER BY ANIMAL_ID; 2023. 2. 26. JOIN>์ํ ๋ณ ์คํ๋ผ์ธ ๋งค์ถ ๊ตฌํ๊ธฐ mysql -- ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์ SELECT A.PRODUCT_CODE, **SUM**(A.PRICE * B.SALES_AMOUNT) AS SALES FROM PRODUCT A **JOIN** OFFLINE_SALE B ON A.PRODUCT_ID = B.PRODUCT_ID **GROUP BY PRODUCT_CODE** ORDER BY SALES DESC, PRODUCT_CODE JOIN = INNER JOIN 2023. 2. 26. JOIN>์กฐ๊ฑด์ ๋ง๋ ๋์์ ์ ์ ๋ฆฌ์คํธ ์ถ๋ ฅํ๊ธฐ mysql -- ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์ SELECT A.BOOK_ID, B.AUTHOR_NAME, DATE_FORMAT(A.PUBLISHED_DATE, '%Y-%m-%d') FROM BOOK A INNER JOIN AUTHOR B ON A.AUTHOR_ID = B.AUTHOR_ID WHERE A.CATEGORY LIKE '๊ฒฝ์ ' ORDER BY A.PUBLISHED_DATE 2023. 2. 26. GROUP BY>๋์ฌ ํ์๊ฐ ๋ง์ ์๋์ฐจ๋ค์ ์๋ณ ๋์ฌ ํ์ ๊ตฌํ๊ธฐ mysql -- SELECT DATE_FORMAT(START_DATE, '%m') AS MONTH, CAR_ID, COUNT(HISTORY_ID) AS RECORDS FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY WHERE CAR_ID IN (SELECT CAR_ID FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY WHERE DATE_FORMAT(START_DATE, '%Y-%m') BETWEEN '2022-08' AND '2022-10' GROUP BY CAR_ID HAVING COUNT(CAR_ID) >= 5 ) GROUP BY MONTH, CAR_ID HAVING RECORDS >= 0 ORDER BY MONTH, CAR_ID DESC; SELECT MO.. 2023. 2. 26. GROUP BY>์นดํ ๊ณ ๋ฆฌ ๋ณ ๋์ ํ๋งค๋ ์ง๊ณํ๊ธฐ mysql -- ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์ SELECT A.CATEGORY, SUM(B.SALES) AS TOTAL_SALES FROM BOOK A INNER JOIN BOOK_SALES B ON A.BOOK_ID = B.BOOK_ID WHERE DATE_FORMAT(B.SALES_DATE, '%Y-%m') LIKE '2022-01' GROUP BY CATEGORY ORDER BY CATEGORY; 2023. 2. 26. GROUP BY>์ฑ๋ถ์ผ๋ก ๊ตฌ๋ถํ ์์ด์คํฌ๋ฆผ ์ด ์ฃผ๋ฌธ๋ mysql ์ ๋๋น -- ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์ SELECT B.INGREDIENT_TYPE, SUM(A.TOTAL_ORDER) AS TOTAL_ORDER FROM FIRST_HALF A INNER JOIN ICECREAM_INFO B WHERE A.FLAVOR = B.FLAVOR GROUP BY B.INGREDIENT_TYPE ORDER BY TOTAL_ORDER; 2023. 2. 26. GROUP BY>์ง๋ฃ๊ณผ๋ณ ์ด ์์ฝ ํ์ ์ถ๋ ฅํ๊ธฐ -- ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์ SELECT MCDP_CD AS '์ง๋ฃ๊ณผ ์ฝ๋', COUNT(*) AS '5์์์ฝ๊ฑด์' FROM APPOINTMENT WHERE APNT_YMD LIKE '2022-05-%' GROUP BY MCDP_CD ORDER BY COUNT(*), MCDP_CD; 2023. 2. 26. ์ด์ 1 ๋ค์ 728x90