https://school.programmers.co.kr/learn/courses/30/lessons/293261
물고기 종류 별 가장 큰 사이즈의 물고기의 ID, FISH_NAME, LENGTH을 조회
SELECT ID, FISH_NAME, LENGTH
FROM FISH_INFO
JOIN FISH_NAME_INFO USING(FISH_TYPE)
WHERE (FISH_TYPE, LENGTH) IN (SELECT FISH_TYPE, MAX(LENGTH) FROM FISH_INFO GROUP BY 1)
ORDER BY 1;
WITH MAX_LENGTH AS(
SELECT FISH_TYPE, MAX(LENGTH) M_LENGTH
FROM FISH_INFO
GROUP BY 1
)
SELECT ID, FISH_NAME, LENGTH
FROM FISH_INFO I
JOIN FISH_NAME_INFO N USING(FISH_TYPE)
JOIN MAX_LENGTH M ON M.FISH_TYPE = I.FISH_TYPE
AND M.M_LENGTH = I.LENGTH
ORDER BY 1;
WITH MAX_LENGTH AS (
SELECT FISH_TYPE, MAX(LENGTH)
FROM FISH_INFO
GROUP BY 1
)
SELECT ID, FISH_NAME, LENGTH
FROM FISH_INFO
JOIN FISH_NAME_INFO USING(FISH_TYPE)
WHERE (FISH_TYPE, LENGTH) IN MAX_LENGTH
ORDER BY 1;