[프로그래머스] 헤비 유저가 소유한 장소

joon_1592·2022년 4월 29일
0

SQL

목록 보기
11/11

host_id당 몇 개의 장소를 소유하는지 임시 테이블 T를 생성하고, places와 조인하여 결과 도출

with 
T as (
    select host_id, count(host_id) as count
    from places
    group by host_id
)

select P.id, P.name, P.host_id
from T join places P on T.host_id = P.host_id
where T.count > 1
order by P.id

서브쿼리 이용

select P.id, P.name, P.host_id
from (
    select host_id, count(host_id) as count
    from places
    group by host_id
) as T join places as P on T.host_id = P.host_id
where T.count > 1
order by id
profile
공부용 벨로그

0개의 댓글