Analytic Functions - 분석함수 예제 (count, rank, keep dense_rank)
▶ 2021.10월에 있었던 BMW Ladies Championship 경기 내용으로 분석
create table BMW_2021(
name varchar2(100),
nation varchar2(100),
total number
);
insert into BMW_2021(name, nation, total)
values('고진영','한국',265);
insert into BMW_2021(name, nation, total)
values('정종','한국',266);
insert into BMW_2021(name, nation, total)
values('뉴질랜드선수','호주.뉴질랜드',271);
insert into BMW_2021(name, nation, total)
values('태종','한국',271);
insert into BMW_2021(name, nation, total)
values('세종','한국',271);
insert into BMW_2021(name, nation, total)
values('문종','한국',271);
insert into BMW_2021(name, nation, total)
values('단종','한국',272);
insert into BMW_2021(name, nation, total)
values('세조','한국',272);
insert into BMW_2021(name, nation, total)
values('America1','미국',273);
insert into BMW_2021(name, nation, total)
values('예종','한국',274);
insert into BMW_2021(name, nation, total)
values('America2','미국',274);
insert into BMW_2021(name, nation, total)
values('태국선수','태국',275);
insert into BMW_2021(name, nation, total)
values('호주선수','호주.뉴질랜드',275);
select BMW_2021.*
, count(*) over (partition by nation) as 나라별인원수
, rank() over(order by total) as 전체랭킹
, rank() over(partition by nation order by total) as 나라별랭킹
, avg(total) over (partition by nation) as 나라별평균타수
, min(total) over (partition by nation) as 나라별_최고점수
, max(name) keep(dense_rank first order by total) over (partition by nation) 나라별최고점수선수
from BMW_2021
order by nation, name
;
select nation,
max(name||' / '||total) keep(dense_rank first ORDER by total) 최고점수선수
from BMW_2021
group by nation
;