Coding Test
[SQL] 보호소에서 중성화한 동물
hyungminjeon
2024. 6. 25. 09:29
[문제]
[해결]
SELECT ai.animal_id, ai.animal_type, ai.name
from animal_ins ai join animal_outs ao on ai.animal_id = ao.animal_id
where ai.sex_upon_intake like "intact%" and (ao.sex_upon_outcome like "Neutered%" or ao.sex_upon_outcome like "Spayed%")
[정리 및 새롭게 알게 된 점]
1. join on 절을 통해 animal_id를 기준으로 animal_ins 테이블과 animal_outs 테이블을 조인하였고
2. where 절에서 like 절을 통해 sex_upon_intake가 intake로 시작하는 행과 sex_upon_outcome이 neutered로 시작하는 행들만을 추출하였다.