습관처럼
programmers [SQL] : JOIN 본문
programmers.co.kr/learn/courses/30/parts/17046
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
2. 있었는데요 없었습니다.
select A.animal_id,A.name
from animal_ins A , animal_outs B
where A.animal_id = B.animal_id and
A.datetime > B.datetime
order by A.datetime
3. 오랜 기간 보호한 동물(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
4. 보호소에서 중성화한 동물
select A.animal_id, A.animal_type, A.name
from animal_ins A ,animal_outs B
where A.animal_id = B.animal_id
and A.sex_upon_intake !=B.sex_upon_outcome
order by A.animal_id
funny SQL~
'Algorithms > programmers' 카테고리의 다른 글
programmers [C++] : 여행경로 (0) | 2020.05.27 |
---|---|
programmers [C++] : 타겟 넘버 (0) | 2020.05.22 |
programmers [SQL] : IS NULL (0) | 2020.05.22 |
programmers [SQL] : GROUP BY (0) | 2020.05.22 |
programmers [SQL] : SUM, MAX, MIN (0) | 2020.05.22 |