알고리즘/프로그래머스
[프로그래머스] SQL고득점킷 _ JOIN
이숭간
2021. 8. 12. 16:15
728x90
1.
-- 코드를 입력하세요
SELECT ANIMAL_ID, NAME
FROM ANIMAL_OUTS
WHERE ANIMAL_ID
NOT IN
(SELECT ANIMAL_INS.ANIMAL_ID
FROM ANIMAL_INS)
ORDER BY ANIMAL_ID;
2.
-- 코드를 입력하세요
SELECT I.ANIMAL_ID, I.NAME
FROM ANIMAL_INS I, ANIMAL_OUTS O
WHERE I.ANIMAL_ID = O.ANIMAL_ID AND I.DATETIME > O.DATETIME #시간이 빠르다 - 작은숫자
ORDER BY I.DATETIME ASC; # 시간이 빠른순 - 오름차순
3.
-- 코드를 입력하세요
SELECT NAME, DATETIME
FROM ANIMAL_INS
WHERE ANIMAL_ID NOT IN (SELECT ANIMAL_ID
FROM ANIMAL_OUTS)
ORDER BY DATETIME ASC
LIMIT 3;
4.
-- 코드를 입력하세요
-- SPAYED - O
-- INTACT - X
-- NEUTERED - O
SELECT I.ANIMAL_ID, I.ANIMAL_TYPE, I.NAME
FROM ANIMAL_INS I, ANIMAL_OUTS O
WHERE I.ANIMAL_ID=O.ANIMAL_ID AND
LEFT(I.SEX_UPON_INTAKE, 1)='I' AND
LEFT(O.SEX_UPON_OUTCOME, 1) !='I'