[퀴즈] 그룹별로 최고점수, 전체건수 및 최고점수 보유자의 건수를 구하고
최고점수를 많이 보유하고 있는 그룹 순서대로 정렬하시오.
WITH t AS
(
SELECT 1 grp, 99 jumsu FROM dual
UNION ALL SELECT 1, 99 FROM dual
UNION ALL SELECT 1, 98 FROM dual
UNION ALL SELECT 1, 97 FROM dual
UNION ALL SELECT 2, 87 FROM dual
UNION ALL SELECT 2, 87 FROM dual
UNION ALL SELECT 2, 87 FROM dual
UNION ALL SELECT 2, 87 FROM dual
UNION ALL SELECT 2, 86 FROM dual
UNION ALL SELECT 3, 76 FROM dual
UNION ALL SELECT 3, 69 FROM dual
UNION ALL SELECT 3, 59 FROM dual
)
SELECT * FROM t;
GRP JUMSU GRP MAX_JUMSU TOT_CNT MAX_CNT
[원본]
[결과]
1
99
2
87
5
4
1
99
1
99
4
2
1
98
3
76
3
1
1
97
2
87
2
87
2
87
2
87
2
86
3
76
3
69
3
59
정답은 몇일뒤에 올리겠습니다.
[정답보기] <=== 트리플클릭
SELECT grp
, MAX(jumsu) jumsu
, COUNT(*) tot_cnt
, COUNT(*) KEEP(DENSE_RANK LAST ORDER BY jumsu) max_cnt
FROM t
GROUP BY grp
ORDER BY max_cnt DESC
;