1. 없어진 기록 찾기
SELECT A.ANIMAL_ID, A.NAME
FROM ANIMAL_OUTS A LEFT JOIN ANIMAL_INS B
ON A.ANIMAL_ID = B.ANIMAL_ID
WHERE B.ANIMAL_ID IS NULL
ORDER BY A.ANIMAL_ID
  1. 있었는데요 없었습니다
SELECT A.ANIMAL_ID, B.NAME from ANIMAL_INS A
LEFT JOIN ANIMAL_OUTS B on A.ANIMAL_ID = B.ANIMAL_ID
WHERE (A.DATETIME - B.DATETIME) > 0
order by A.DATETIME;
  1. 오랜 기간 보호한 동물(1)
SELECT A.NAME, A.DATETIME from ANIMAL_INS A
LEFT JOIN ANIMAL_OUTS B
ON A.ANIMAL_ID = B.ANIMAL_ID
where B.ANIMAL_ID is null
order by A.DATETIME
limit 3;
  1. 보호소에서 중성화한 동물
SELECT A.ANIMAL_ID, A.ANIMAL_TYPE, A.NAME from ANIMAL_INS A
RIGHT JOIN ANIMAL_OUTS B on B.ANIMAL_ID = A.ANIMAL_ID
 WHERE A.SEX_UPON_INTAKE like '%Intact%' and
     (B.SEX_UPON_OUTCOME like '%Spayed%' or B.SEX_UPON_OUTCOME like '%Neutered%')