๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€์ด(SQL)

์ด๋ฆ„์ด ์—†๋Š” ๋™๋ฌผ์˜ ์•„์ด๋””

by carrot0911 2024. 11. 6.

๋ฌธ์ œ ์„ค๋ช…

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

NAME TYPE NULLABLE
ANIMAL_ID VARCHAR(N) FALSE
ANIMAL_TYPE VARCHAR(N) FALSE
DATETIME DATETIME FALSE
INTAKE_CONDITION VARCHAR(N) FALSE
NAME VARCHAR(N) TRUE
SEX_UPON_INTAKE VARCHAR(N) FALSE

๋™๋ฌผ ๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜จ ๋™๋ฌผ ์ค‘, ์ด๋ฆ„์ด ์—†๋Š” ์ฑ„๋กœ ๋“ค์–ด์˜จ ๋™๋ฌผ์˜ ID๋ฅผ ์กฐํšŒํ•˜๋Š” SQL ๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ๋‹จ, ID๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ

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

ANIMAL
_ID
ANIMAL
_TYPE
DATETIME INTAKE_
CONDITION
NAME SEX_UPON
_INTAKE
A368930 Dog 2014-06-08 13:20:00 Normal NULL Spayed Female
A524634 Dog 2015-01-02 18:54:00 Normal *Belle Intact Female
A465637 Dog 2017-06-04 08:17:00 Injured *Commander Neutered Male

์ด๋ฆ„์ด ์—†๋Š” ์ฑ„๋กœ ๋“ค์–ด์˜จ ๋™๋ฌผ์˜ ID๋Š” A368930์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ SQL์„ ์‹คํ–‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถœ๋ ฅ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ์ฝ”๋“œ

SELECT ANIMAL_ID
FROM ANIMAL_INS
WHERE NAME IS NULL
ORDER BY ANIMAL_ID ASC;

์ฝ”๋“œ ์„ค๋ช…

  • SELECT ANIMAL_ID : ANIMAL_ID์„ ์„ ํƒํ•œ๋‹ค.
  • FROM ANIMAL_INS : ANIMAL_INS ํ…Œ์ด๋ธ”์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์กฐํšŒํ•œ๋‹ค.
  • WHERE NAME IS NULL : ์ด๋ฆ„์ด ์—†๋Š” ๋™๋ฌผ๋“ค์„ ์กฐํšŒํ•œ๋‹ค.
  • ORDER BY ANIMAL_ID ASC : ANIMAL_ID ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ๋‹ค.