6๏ธโฃ SQL/Problem Solving8 [MySQL] Programmers Lv.3 ์ ์ฒด ๋ฌธ์ ํ์ด ์์ด์ง ๊ธฐ๋ก ์ฐพ๊ธฐ -- join ๋ฏธ์ฌ์ฉ SELECT ANIMAL_ID, NAME FROM ANIMAL_OUTS WHERE ANIMAL_ID NOT IN ( SELECT ANIMAL_ID FROM ANIMAL_INS) -- join ์ฌ์ฉ SELECT OUTS.ANIMAL_ID, OUTS.NAME FROM ANIMAL_OUTS AS OUTS LEFT OUTER JOIN ANIMAL_INS AS INS ON OUTS.ANIMAL_ID = INS.ANIMAL_ID WHERE INS.ANIMAL_ID IS NULL ORDER BY OUTS.ANIMAL_ID ๐ JOIN ์ฌ์ฉํ ๋๋ ๊ฐ ํ ์ด๋ธ์ ์ด๋ฆ ๋ถ์ฌ์ ์จ์ฃผ๊ณ , ON์ผ๋ก ์ธ๋ํค ๋ง์ถฐ์ฃผ๊ธฐ ๐ OUTER JOIN ์ฌ์ฉํ๋ฉด ์๋ก ์ด๋ค ์ฐจ์ด๊ฐ ์๋์ง ์ ์ ์์ (h.. 2022. 2. 2. [MySQL] Programmers Lv.2 ์ ์ฒด ๋ฌธ์ ํ์ด ๊ณ ์์ด์ ๊ฐ๋ ๋ช ๋ง๋ฆฌ ์์๊น SELECT ANIMAL_TYPE, COUNT(ANIMAL_TYPE) AS "count" FROM ANIMAL_INS GROUP BY ANIMAL_TYPE ORDER BY ANIMAL_TYPE ์ต์๊ฐ ๊ตฌํ๊ธฐ SELECT MIN(DATETIME) AS "์๊ฐ" FROM ANIMAL_INS ์ด๋ฆ์ el์ด ๋ค์ด๊ฐ๋ ๋๋ฌผ ์ฐพ๊ธฐ SELECT ANIMAL_ID, NAME FROM ANIMAL_INS WHERE NAME LIKE "%el%" AND ANIMAL_TYPE = "Dog" ORDER BY NAME ๐ LIKE๋ ๋ฌธ์์ด์ ํจํด์ ๊ฒ์ํ๋ ์ญํ ๐ SQL์ ๊ธฐ๋ณธ์ ์ผ๋ก ๋์๋ฌธ์ ๊ตฌ๋ถํ์ง ์์ ์ ์ ์๊ฐ ๊ตฌํ๊ธฐ(1) SELECT HOUR(DATETIME) AS "HOUR", COUN.. 2022. 2. 2. [MySQL] Programmers Lv.1 ์ ์ฒด ๋ฌธ์ ํ์ด ๋ชจ๋ ๋ ์ฝ๋ ์กฐํํ๊ธฐ SELECT * FROM ANIMAL_INS ORDER BY ANIMAL_ID ๐ SQL ๋ฌธ์ ์ ๊ฒฝ์ฐ ๋ฑ ํ๋์ ๋ฐ์ดํฐ๋ง ์ถ๋ ฅํ๋ ๊ฒฝ์ฐ๋ฅผ ์ ์ธํ๊ณ ๋ ORDER BY๋ฅผ ํ์๋ก ์๊ฐํ์. ์ด๋ฆ์ด ์๋ ๋๋ฌผ์ ์์ด๋ SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NULL ORDER BY ANIMAL_ID ๐ NULL์ ์ฒดํฌํ ๋๋ ๋น๊ต ์ฐ์ฐ์๋ก IS ๋๋ IS NOT์ ์ฌ์ฉ ! ์ด๋ฆ์ด ์๋ ๋๋ฌผ์ ์์ด๋ SELECT ANIMAL_ID FROM ANIMAL_INS WHERE NAME IS NOT NULL ORDER BY ANIMAL_ID ์ด๋ฆฐ ๋๋ฌผ ์ฐพ๊ธฐ SELECT ANIMAL_ID, NAME FROM ANIMAL_INS WHERE INTAKE_COND.. 2022. 2. 2. ์ด์ 1 2 ๋ค์