๐Ÿฃ๐Ÿค๐Ÿ“[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜ค๋žœ ๊ธฐ๊ฐ„ ๋ณดํ˜ธํ•œ ๋™๋ฌผ

๋ฌธ์ œ ์„ค๋ช…

ANIMAL_INS ํ…Œ์ด๋ธ”์€ ๋™๋ฌผ ๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜จ ๋™๋ฌผ์˜ ์ •๋ณด๋ฅผ ๋‹ด์€ ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค. ANIMAL_INS ํ…Œ์ด๋ธ” ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์œผ๋ฉฐ, ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, SEX_UPON_INTAKE๋Š” ๊ฐ๊ฐ ๋™๋ฌผ์˜ ์•„์ด๋””, ์ƒ๋ฌผ ์ข…, ๋ณดํ˜ธ ์‹œ์ž‘์ผ, ๋ณดํ˜ธ ์‹œ์ž‘ ์‹œ ์ƒํƒœ, ์ด๋ฆ„, ์„ฑ๋ณ„ ๋ฐ ์ค‘์„ฑํ™” ์—ฌ๋ถ€๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

ANIMAL_OUTS ํ…Œ์ด๋ธ”์€ ๋™๋ฌผ ๋ณดํ˜ธ์†Œ์—์„œ ์ž…์–‘ ๋ณด๋‚ธ ๋™๋ฌผ์˜ ์ •๋ณด๋ฅผ ๋‹ด์€ ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค. ANIMAL_OUTS ํ…Œ์ด๋ธ” ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์œผ๋ฉฐ, ANIMAL_ID, ANIMAL_TYPE, DATETIME, NAME, SEX_UPON_OUTCOME๋Š” ๊ฐ๊ฐ ๋™๋ฌผ์˜ ์•„์ด๋””, ์ƒ๋ฌผ ์ข…, ์ž…์–‘์ผ, ์ด๋ฆ„, ์„ฑ๋ณ„ ๋ฐ ์ค‘์„ฑํ™” ์—ฌ๋ถ€๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ANIMAL_OUTS ํ…Œ์ด๋ธ”์˜ ANIMAL_ID๋Š” ANIMAL_INS์˜ ANIMAL_ID์˜ ์™ธ๋ž˜ ํ‚ค์ž…๋‹ˆ๋‹ค.

์•„์ง ์ž…์–‘์„ ๋ชป ๊ฐ„ ๋™๋ฌผ ์ค‘, ๊ฐ€์žฅ ์˜ค๋ž˜ ๋ณดํ˜ธ์†Œ์— ์žˆ์—ˆ๋˜ ๋™๋ฌผ 3๋งˆ๋ฆฌ์˜ ์ด๋ฆ„๊ณผ ๋ณดํ˜ธ ์‹œ์ž‘์ผ์„ ์กฐํšŒํ•˜๋Š” SQL๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ์ด๋•Œ ๊ฒฐ๊ณผ๋Š” ๋ณดํ˜ธ ์‹œ์ž‘์ผ ์ˆœ์œผ๋กœ ์กฐํšŒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ

์˜ˆ๋ฅผ ๋“ค์–ด, ANIMAL_INS ํ…Œ์ด๋ธ”๊ณผ ANIMAL_OUTS ํ…Œ์ด๋ธ”์ด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค๋ฉด

ANIMAL_INS

ANIMAL_OUTS

SQL๋ฌธ์„ ์‹คํ–‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‚˜์™€์•ผ ํ•ฉ๋‹ˆ๋‹ค.

โ€ป ์ž…์–‘์„ ๊ฐ€์ง€ ๋ชปํ•œ ๋™๋ฌผ์ด 3๋งˆ๋ฆฌ ์ด์ƒ์ธ ๊ฒฝ์šฐ๋งŒ ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

ํ’€์ด ์‹œ์ž‘

SELECT NAME, DATETIME 
FROM ANIMAL_INS 
WHERE ANIMAL_ID NOT IN(SELECT ANIMAL_ID FROM ANIMAL_OUTS) 
ORDER BY DATETIME 
LIMIT 3;
  1. ANIMAL_INS ์—๋Š” ์žˆ์ง€๋งŒ ANIMAL_OUTS ์—๋Š” ์—†๋Š” ANIMAL_ID ์˜ ์ปฌ๋Ÿผ๋“ค์ด ์ž…์–‘์„ ๊ฐ€์ง€ ๋ชปํ•œ ์ปฌ๋Ÿผ

  2. DATETIME ๊ธฐ์ค€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ 3๊ฐœ๊นŒ์ง€๋งŒ ์กฐํšŒ

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ