문제 URL : https://solvesql.com/problems/multiple-medalist/

 

https://solvesql.com/problems/multiple-medalist/

 

solvesql.com

 

*문제 저작권으로 인하여 직접 작성한 쿼리문만 첨부

select athletes.name
from athletes, records, games
where athletes.id = records.athlete_id
and records.game_id = games.id
and medal is not null
and year >= 2000
group by athlete_id
having count(distinct team_id) > 1
order by name

 

3개의 테이블을 조인하기 위하여 WHERE절을 이용한 Multiple Joins를 적용

count(~)를 where절 내에 작성했다가 "misuse of aggregate: count()" 오류 발생 -> having절 내에 작성하여 해결 

+ Recent posts