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

Updated:

가장 오랜 기간 보호된 동물의 차이를 구해야 하는데, 시간단위차이를 빼주는 명령어가 있다고 한다

datediff라는 명령어이다. datediff(시간a,시간b)라고 쓴다. 시간a가 시간b보다 반드시 빠르지않아도된다.
시간 순서는 상관없음!!

by SQL

-- 코드를 입력하세요
SELECT a.ANIMAL_ID, a.NAME
from animal_ins a, animal_outs b
where a.animal_id = b.animal_id
order by datediff(a.datetime,b.datetime) limit 2

Leave a comment