๐Ÿ’ SQL/Group By

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][SQL] ํ—ค๋น„ ์œ ์ €๊ฐ€ ์†Œ์œ ํ•œ ์žฅ์†Œ

์„ ๋‹ฌ 2023. 5. 25. 23:49
๋ฐ˜์‘ํ˜•

https://school.programmers.co.kr/learn/courses/30/lessons/77487

 

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

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

programmers.co.kr

 

๋ฌธ์ œ

์ด ์„œ๋น„์Šค์—์„œ๋Š” ๊ณต๊ฐ„์„ ๋‘˜ ์ด์ƒ ๋“ฑ๋กํ•œ ์‚ฌ๋žŒ์„ "ํ—ค๋น„ ์œ ์ €"๋ผ๊ณ  ๋ถ€๋ฆ…๋‹ˆ๋‹ค.

ํ—ค๋น„ ์œ ์ €๊ฐ€ ๋“ฑ๋กํ•œ ๊ณต๊ฐ„์˜ ์ •๋ณด๋ฅผ

์•„์ด๋”” ์ˆœ์œผ๋กœ ์กฐํšŒํ•˜๋Š” SQL๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

 

ํ’€์ด

-- ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”
select *
from PLACES
where HOST_ID in (
    SELECT HOST_ID
    from PLACES
    group by HOST_ID having count(HOST_ID) >= 2 )
order by ID

 

๋ฐ˜์‘ํ˜•