프로그래머스 사이트 링크
문제
코드
ver(1) - LEFT JOIN 사용
SELECT A.NAME, A.DATETIME
FROM ANIMAL_INS AS A
LEFT
JOIN ANIMAL_OUTS AS B
ON A.ANIMAL_ID = B.ANIMAL_ID
WHERE B.ANIMAL_ID IS NULL
ORDER BY A.DATETIME
LIMIT 3
ver(2) - NOT EXISTS 사용
SELECT NAME, DATETIME
FROM ANIMAL_INS A
WHERE NOT EXISTS ( SELECT 1 FROM ANIMAL_OUTS B WHERE A.ANIMAL_ID = B.ANIMAL_ID)
ORDER BY DATETIME
LIMIT 3;
ver(3) - NOT IN 사용
SELECT NAME, DATETIME
FROM ANIMAL_INS A
WHERE A.ANIMAL_ID NOT IN (SELECT B.ANIMAL_ID FROM ANIMAL_OUTS B )
ORDER BY DATETIME
LIMIT 3;
댓글남기기