WITH T AS ( SELECT 2023 Y, 1 M, 1 W, 7 VV FROM DUAL UNION ALL SELECT 2023, 1, 2, 8 FROM DUAL UNION ALL SELECT 2023, 1, 3, 9 FROM DUAL UNION ALL SELECT 2023, 1, 4, 6 FROM DUAL UNION ALL SELECT 2023, 1, 5, 10 FROM DUAL UNION ALL SELECT 2023, 2, 6, 11 FROM DUAL UNION ALL SELECT 2023, 2, 7, 5 FROM DUAL UNION ALL SELECT 2023, 2, 8, 11 FROM DUAL UNION ALL SELECT 2023, 2, 9, 9 FROM DUAL UNION ALL SELECT 2023, 3, 10, 10 FROM DUAL ) SELECT Y, M, W, VV FROM T WHERE W IN ( SELECT MAX(W) FROM T GROUP BY Y, M );
위의 쿼리를 좀 더 개선 할 수 있을까요?
같은 테이블을 두번 접근 하게 되는데 저 방법 외에 좀 더 좋은 방법이 있을 것 같아서요.
감사합니다.