1.
-Answer
SELECT AI.ANIMAL_ID, AO.NAME
FROM ANIMAL_INS AI
JOIN ANIMAL_OUTS AO ON AI.ANIMAL_ID=AO.ANIMAL_ID
ORDER BY (AO.DATETIME-AI.DATETIME) DESC
LIMIT 2
-Code
Limit2: 2개만 보기 위해서 limit 씀
2.
-Answer:
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 "%Spayed%" or AO.SEX_UPON_OUTCOME like '%Neutered%')
ORDER BY AI.ANIMAL_ID
;
-code:
SELECT I.ANIMAL_ID, I.ANIMAL_TYPE, I.NAME FROM ANIMAL_INS I
JOIN ANIMAL_OUTS O ON O.ANIMAL_ID = I.ANIMAL_ID
WHERE I.SEX_UPON_INTAKE LIKE 'Intact%'
AND (O.SEX_UPON_OUTCOME LIKE 'Spayed%' OR O.SEX_UPON_OUTCOME LIKE 'Neutered%')
ORDER BY I.ANIMAL_ID;
And 쓸때 () 붙이기
'SQL 문제들' 카테고리의 다른 글
SQL 문제(Case, Join) (0) | 2024.11.21 |
---|---|
SQL 문제들(join 문제들) (0) | 2024.11.19 |
sql 문제1 (0) | 2024.11.16 |
SQL 세션 문제2(해결중) (1) | 2024.10.17 |