[SQL문제풀기] 멀티 플랫폼 게임 찾기

silver's avatar
Mar 15, 2025
[SQL문제풀기] 멀티 플랫폼 게임 찾기
Contents
문제SQLite

문제

SQLite

내가 작성한 오답

notion image
'Sony','Nintendo','Microsoft'은 제작사였고 그 옆이 플랫폼이었다. 제작사가 같으면 같은 플랫폼 계열로 묶는 거였다.
notion image
select distinct g.name from games g join platforms p on g.platform_id = p.platform_id and p.name in ('Sony','Nintendo','Microsoft') where g.year >= 2012 group by g.name having count(p.platform_id) >= 2

내가 작성한 정답

select distinct g.name from games g join platforms p on g.platform_id = p.platform_id and p.name in ('PS3', 'PS4', 'PSP', 'PSV', 'Wii', 'WiiU', 'DS', '3DS','X360', 'XONE') where g.year >= 2012 group by g.name having count (distinct case when p.name in ('PS3', 'PS4', 'PSP', 'PSV') then 'Sony' when p.name in ('Wii', 'WiiU', 'DS', '3DS') then 'Nintendo' when p.name in ( 'X360', 'XONE') then 'Microsoft' end) >= 2
위에서 on 조건으로 p.name에 메이저 플랫폼이 아닌 걸 이미 걸렀기 때문에 else 사용가능, g.name 으로 group by 했기 때문에 select절에 distinct 사용하지 않아도 됨
select g.name from games g join platforms p on g.platform_id = p.platform_id and p.name in ('PS3', 'PS4', 'PSP', 'PSV', 'Wii', 'WiiU', 'DS', '3DS','X360', 'XONE') where g.year >= 2012 group by g.name having count (distinct case when p.name in ('PS3', 'PS4', 'PSP', 'PSV') then 'Sony' when p.name in ('Wii', 'WiiU', 'DS', '3DS') then 'Nintendo' else 'Microsoft' end) >= 2
 
Share article

silver