쥬로그
Programmers SQL 고득점 Kit - JOIN (MySQL) 본문
반응형
JOIN > 없어진 기록 찾기
SELECT OUTS.ANIMAL_ID, OUTS.NAME FROM ANIMAL_OUTS OUTS
LEFT OUTER JOIN ANIMAL_INS INS
ON OUTS.ANIMAL_ID = INS.ANIMAL_ID
WHERE INS.ANIMAL_ID IS NULL
ORDER BY OUTS.ANIMAL_ID;
JOIN > 있었는데요 없었습니다
SELECT INS.ANIMAL_ID, INS.NAME FROM ANIMAL_INS INS JOIN ANIMAL_OUTS OUTS
ON INS.ANIMAL_ID = OUTS.ANIMAL_ID
WHERE INS.DATETIME > OUTS.DATETIME ORDER BY INS.DATETIME ASC;
JOIN > 오랜 기간 보호한 동물(1)
SELECT INS.NAME, INS.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 ASC
LIMIT 3;
JOIN > 보호소에서 중성화한 동물
SELECT INS.ANIMAL_ID, INS.ANIMAL_TYPE, INS.NAME FROM ANIMAL_INS INS
JOIN ANIMAL_OUTS OUTS
ON INS.ANIMAL_ID = OUTS.ANIMAL_ID
WHERE INS.SEX_UPON_INTAKE LIKE '%Intact%' AND
(OUTS.SEX_UPON_OUTCOME LIKE '%Neutered%' OR OUTS.SEX_UPON_OUTCOME LIKE '%Spayed%')
ORDER BY INS.ANIMAL_ID ASC;
SELECT INS.ANIMAL_ID, INS.ANIMAL_TYPE, INS.NAME FROM ANIMAL_INS INS
JOIN ANIMAL_OUTS OUTS
ON INS.ANIMAL_ID = OUTS.ANIMAL_ID
WHERE INS.SEX_UPON_INTAKE LIKE '%Intact%' AND
OUTS.SEX_UPON_OUTCOME REGEXP 'Neutered|Spayed'
ORDER BY INS.ANIMAL_ID ASC;
반응형
'Algorithm > Programmers' 카테고리의 다른 글
Programmers 코딩테스트 고득점 Kit - 해시 (0) | 2022.06.01 |
---|---|
Programmers SQL 고득점 Kit - String, Date (MySQL) (0) | 2022.05.31 |
Programmers SQL 고득점 Kit - IS NULL (MySQL) (0) | 2022.05.31 |
Programmers SQL 고득점 Kit - GROUP BY (MySQL) (0) | 2022.05.31 |
Programmers SQL 고득점 Kit - SUM, MAX, MIN (MySQL) (0) | 2022.05.31 |