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

Data Science LAB

[MySQL] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต 13(๋™๋ช… ๋™๋ฌผ ์ˆ˜ ์ฐพ๊ธฐ) ๋ณธ๋ฌธ

๐Ÿ“ Coding Test/MySQL

[MySQL] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต 13(๋™๋ช… ๋™๋ฌผ ์ˆ˜ ์ฐพ๊ธฐ)

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


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

 

 

 

 

 

 

์˜ˆ์‹œ

 

 

 

 

 

 

 

๋ฌธ์ œ ํ’€์ด
SELECT NAME, COUNT(*)
FROM ANIMAL_INS
WHERE NAME IS NOT NULL
GROUP BY NAME
HAVING COUNT(NAME)>1
ORDER BY NAME

์ด๋ฆ„์ด ์—†๋Š” ๋™๋ฌผ์€ ์ œ์™ธํ•ด์•ผ ํ•˜๋ฏ€๋กœ WHERE NAME IS NOT NULL

 

NAME์ปฌ๋Ÿผ์œผ๋กœ ๊ทธ๋ฃน ์ง€์€ ํ›„

HAVING COUNT(NAME) > 1 ๋กœ ์ค‘๋ณต๋œ ์ด๋ฆ„์˜ ๋ฐ์ดํ„ฐ ์กฐํšŒ

 

728x90
Comments