250x250
Link
๋‚˜์˜ GitHub Contribution ๊ทธ๋ž˜ํ”„
Loading data ...
Notice
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Data Science LAB

[MySQL]ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต2(์ตœ๊ทผ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ) ๋ณธ๋ฌธ

๐Ÿ“ Coding Test/MySQL

[MySQL]ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต2(์ตœ๊ทผ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ)

ใ…… ใ…œ ใ…” ใ…‡ 2022. 2. 7. 10:15
728x90

ํŒŒ์ด์ฌ์ด๋‚˜ R์— ๋น„ํ•ด MySQL์€ ๊ณต๋ถ€๋ฅผ ์ž˜ ์•ˆํ•ด์„œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์— ์˜ฌ๋ผ์™€์žˆ๋Š” ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๋ฌธ์ œ๋ผ๋„ ํ’€์–ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹น!!

 

 

๋ฌธ์ œ

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

๊ฐ€์žฅ ์ตœ๊ทผ์— ๋“ค์–ด์˜จ ๋™๋ฌผ์€ ์–ธ์ œ ๋“ค์–ด์™”๋Š”์ง€ ์กฐํšŒํ•˜๋Š” SQL ๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

 

์˜ˆ์‹œ)

 

 

ํ’€์ด

SELECT DATETIME AS '์‹œ๊ฐ„'
FROM ANIMAL_INS
ORDER BY DATETIME DESC LIMIT 1

1. DATETIME ์กฐํšŒ ํ›„ '์‹œ๊ฐ„'์œผ๋กœ ์ด๋ฆ„ ์„ค์ •

 

2. ๊ฐ€์žฅ ์ตœ๊ทผ ๋ฐ์ดํ„ฐ ์„ ํƒํ•˜๋Š” ๋ฒ• => ORDER BY [์ปฌ๋Ÿผ๋ช…] DESC LIMIT [์ถœ๋ ฅ๊ฐœ์ˆ˜]

728x90
Comments