[SQL] programmers 물고기 종류 별 대어 찾기

도리·2025년 4월 23일

약간 헤맸다...

  • 정답코드
  1. max_length 뽑고
  2. self join해서 id, fish_type, length(max임) 뽑고
  3. 그 다음 name info랑 join해서 type-> name으로 바꿔치기.
with max_length as (
select fish_type, max(length) as length
from fish_info
group by fish_type)
,type_info as (
select i.id, m.fish_type, m.length 
from max_length m 
join fish_info i on i.fish_type = m.fish_type
where  i.length = m.length)
select ti.id, ni.fish_name, ti.length
from type_info ti join fish_name_info ni on ti.fish_type = ni.fish_type
order by id
profile
인공지능응용학과 졸업예정..

0개의 댓글