[ํ๋ก๊ทธ๋๋จธ์ค] ์ค๋ ๊ธฐ๊ฐ ๋ณดํธํ ๋๋ฌผ(1) (SQL/JOIN)
SELECT A.NAME, A.DATETIME // ANIMAL_INS์ ์๋ NAME, DATETIME ์กฐํ
FROM ANIMAL_INS A
LEFT OUTER JOIN ANIMAL_OUTS B
ON A.ANIMAL_ID = B.ANIMAL_ID
WHERE B.ANIMAL_ID IS NULL // ANIMAL_INS์๋ง ์๋ ANIMAL_ID
ORDER BY A.DATETIME ASC // ๋ณดํธ ์์์ผ ์ ์ ๋ ฌ
LIMIT 3; // ๊ฐ์ฅ ์ค๋ ์์๋ 3๋ง๋ฆฌ๋ก ์ ํ
์ ์ ๋ชป ๊ฐ ๋๋ฌผ: ANIMAL_ID๊ฐ ANIMAL_OUTS์๋ ์๋๋ฐ ANIAML_INS์๋ ์๋(WHERE B.ANIMAL_ID IS NULL) LEFT OUTER JOIN์ ํด๋นํ๋ค.
๋ณดํธ ์์์ผ ์ ์ ๋ ฌ: ORDER BY A.DATETIME ASC
๊ฐ์ฅ ์ค๋ ์์๋ 3๋ง๋ฆฌ: ORDER BY๋ก ์ ๋ ฌ๋ ๊ฒ์์ LIMIT 3๋ฅผ ํ๋ฉด ๊ฐ์ฅ ์ค๋ ์์๋ 3๋ง๋ฆฌ๋ง ์กฐํํ ์ ์๋ค.
[HackerRank] Asian Population (SQL/JOIN) (0) | 2021.02.01 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ณดํธ์์์ ์ค์ฑํํ ๋๋ฌผ (SQL/JOIN) (0) | 2021.01.30 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์์๋๋ฐ์ ์์์ต๋๋ค (SQL/JOIN) (0) | 2021.01.23 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ด์ง ๊ธฐ๋ก ์ฐพ๊ธฐ (SQL/JOIN) (0) | 2021.01.23 |
[HackerRank] Weather Observation Station 4 (SQL) (0) | 2021.01.14 |