ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

๋ฌธ์ œ ํ’€์ด

MySQL์—์„œ `SELECT`๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค์˜ ๋‹ค์–‘ํ•œ ๋ ˆ์ฝ”๋“œ๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋•Œ ์ฐพ๊ณ ์ž ํ•˜๋Š” ํ•„๋“œ๋ฅผ ์„ ํƒํ•˜๋Š” ๊ฒƒ์€ `SELECT`๋ฅผ ํ†ตํ•ด ํ•˜๋ฉฐ, `ORDER BY`, `GROUP BY`์™€ ๊ฐ™์€ ๊ฒƒ์„ ํ™œ์šฉํ•˜์—ฌ ์กฐ๊ฑด์— ๋งž๊ฒŒ ํ•„๋“œ๋“ค์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ฝ”๋“œ

๋ชจ๋“  ๋ ˆ์ฝ”๋“œ ์กฐํšŒ ํ•˜๊ธฐ

SELECT *
FROM ANIMAL_INS

 

์—ญ์ˆœ ์ •๋ ฌํ•˜๊ธฐ

SELECT NAME, DATETIME
FROM ANIMAL_INS 
ORDER BY ANIMAL_ID DESC

 

์•„ํ”ˆ ๋™๋ฌผ ์ฐพ๊ธฐ

SELECT ANIMAL_ID, NAME
FROM ANIMAL_INS
WHERE INTAKE_CONDITION = 'Sick'

 

์–ด๋ฆฐ ๋™๋ฌผ ์ฐพ๊ธฐ

SELECT ANIMAL_ID, NAME
FROM ANIMAL_INS
WHERE INTAKE_CONDITION != 'Aged'

 

๋™๋ฌผ์˜ ์•„์ด๋””์™€ ์ด๋ฆ„

SELECT ANIMAL_ID, NAME
FROM ANIMAL_INS
ORDER BY ANIMAL_ID

 

์—ฌ๋Ÿฌ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๊ธฐ

SELECT ANIMAL_ID, NAME, DATETIME
FROM ANIMAL_INS
ORDER BY NAME, DATETIME DESC

 

์ƒ์œ„ n๊ฐœ ๋ ˆ์ฝ”๋“œ

SELECT NAME
FROM ANIMAL_INS
ORDER BY DATETIME
LIMIT 1

 

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€