SQL 고득점 Kit - JOIN

JOIN

https://programmers.co.kr/learn/courses/30/parts/17046

없어진 기록 찾기

SELECT OUTS.ANIMAL_ID as ANIMAL_ID, OUTS.NAME as NAME
FROM ANIMAL_OUTS OUTS
LEFT JOIN ANIMAL_INS INS
ON OUTS.ANIMAL_ID = INS.ANIMAL_ID
WHERE INS.ANIMAL_ID IS NULL

있었는데요 없었습니다

SELECT OUTS.ANIMAL_ID AS ANIMAL_ID, OUTS.NAME AS NAME
FROM ANIMAL_OUTS OUTS
LEFT JOIN ANIMAL_INS INS
ON INS.ANIMAL_ID = OUTS.ANIMAL_ID
WHERE INS.DATETIME > OUTS.DATETIME
ORDER BY INS.DATETIME

오랜 기간 보호한 동물(1)

SELECT INS.NAME NAME, INS.DATETIME DATETIME
FROM ANIMAL_INS INS
LEFT JOIN ANIMAL_OUTS OUTS
ON INS.ANIMAL_ID = OUTS.ANIMAL_ID
WHERE OUTS.ANIMAL_ID IS NULL
ORDER BY INS.DATETIME
LIMIT 3

보호소에서 중성화한 동물

SELECT INS.ANIMAL_ID ANIMAL_ID, INS.ANIMAL_TYPE ANIMAL_TYPE, INS.NAME NAME
FROM ANIMAL_INS INS
LEFT JOIN ANIMAL_OUTS OUTS
ON INS.ANIMAL_ID = OUTS.ANIMAL_ID
WHERE (OUTS.ANIMAL_ID IS NOT NULL AND INS.SEX_UPON_INTAKE != OUTS.SEX_UPON_OUTCOME)
ORDER BY INS.ANIMAL_ID

좋은 웹페이지 즐겨찾기