SELECT A.ANIMAL_ID, A.NAME
FROM ANIMAL_INS A
INNER JOIN ANIMAL_OUTS B
ON A.ANIMAL_ID = B.ANIMAL_ID
WHERE A.DATETIME > B.DATETIME
ORDER BY A.DATETIME ASC;
ANIMAL_ID๋ฅผ ๊ธฐ์ค์ผ๋ก INNER JOIN์ ํ๋ค.
WHERE: ๊ฑฐ๊ธฐ์์ ANIMAL_INS.DATETIME > ANIMAL_OUTS.DATETIME์ธ ์กฐ๊ฑด์ ์กฐํํ๋ค.
ORDER BY: ANIMAL_INS ๊ธฐ์ค DATETIME์ผ๋ก ์ ๋ ฌํ๋ค.
SELECT A.ANIMAL_ID, A.NAME, A.DATETIME AS in_time, B.DATETIME AS out_time
FROM ANIMAL_INS A
INNER JOIN ANIMAL_OUTS B
ON A.ANIMAL_ID = B.ANIMAL_ID
WHERE A.DATETIME > B.DATETIME
ORDER BY A.DATETIME ASC;
์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๋ ์์ ๊ฐ์ด ๋์จ๋ค.
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ณดํธ์์์ ์ค์ฑํํ ๋๋ฌผ (SQL/JOIN) (0) | 2021.01.30 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ์ค๋ ๊ธฐ๊ฐ ๋ณดํธํ ๋๋ฌผ(1) (SQL/JOIN) (0) | 2021.01.30 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ด์ง ๊ธฐ๋ก ์ฐพ๊ธฐ (SQL/JOIN) (0) | 2021.01.23 |
[HackerRank] Weather Observation Station 4 (SQL) (0) | 2021.01.14 |
[ํ๋ก๊ทธ๋๋จธ์ค] NULL ์ฒ๋ฆฌํ๊ธฐ (SQL/IS NULL) (0) | 2021.01.11 |