https://school.programmers.co.kr/learn/courses/30/lessons/293261
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
처음에 아래와 같이 했더니 컴파일 에러가 발생했다.
select id, fish_name, max(length)
from fish_info natural join fish_name_info
group by fish_name
order by id
length를 max로 설정해줘서 이에 해당하는 id값으로 도출될 줄 알았지만, 안 되었고 따라서 아래와 같이 where 절에 서브쿼리로 두어서 max에 해당하는 length를 가지는 레코드를 찾도록 구현했다.
select id, fish_name, length
from fish_info natural join fish_name_info
where (fish_type, length) in (select fish_type, max(length)
from fish_info natural join fish_name_info
group by fish_type)
order by id
'코딩테스트 > MySQL' 카테고리의 다른 글
[프로그래머스 Level 4] 보호소에서 중성화한 동물 (MySQL) (0) | 2024.11.25 |
---|---|
[프로그래머스 Level 3] 대장균의 크기에 따라 분류하기 2 (MySQL) (feat. NTILE) (0) | 2024.11.24 |
[프로그래머스 Level 3] 업그레이드 할 수 없는 아이템 구하기 (MySQL) (0) | 2024.11.22 |
[프로그래머스 Level 3] 대장균들의 자식의 수 구하기 (MySQL) (0) | 2024.11.20 |
[프로그래머스 Level 3] 특정 조건을 만족하는 물고기별 수와 최대 길이 구하기(MySQL) (0) | 2024.11.17 |