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