'oracle 통계'에 해당되는 글 1건

  1. 2012.09.21 Oracle over() 구문
02.Oracle/DataBase2012. 9. 21. 05:23
반응형

WITH TEST AS
(
select 'A' grade, 10 cnt from dual union all
select 'A' grade, 20 cnt from dual union all
select 'A' grade, 15 cnt from dual union all
select 'B' grade, 20 from dual union all
select 'B' grade, 30 from dual union all
select 'D' grade, 15 from dual union all
select 'F' grade, 10 from dual
)
SELECT
grade 등급,
cnt 학생수,
sum(cnt) over () 갯수,
row_number() over(partition by grade order by cnt) 로넘,
rank() over(partition by grade order by cnt) 랭크,
round((cnt / sum(cnt) over ())*100,2) 구성비,
sum(cnt) over (partition by grade order by grade) 누적학생수,
sum(cnt) over (partition by grade,cnt order by grade) 그레카운,
sum(cnt) over (order by grade) 누적,
round((sum(cnt) over (order by grade)/sum(cnt) over ())*100,2) 누적구성비
FROM TEST;

/*

rank() over(partition by grade order by cnt) 랭크,

표현식 over (partition by 컬럼1 order by 컬럼2)

이 의미는

"(컬럼1값이 같은놈들로 묶은것을 컬럼2로 정렬한) 각 파티션별로 표현식을 수행해준다."

*/

복잡하군... :(

[출처] Oracle over() 구문|작성자 18061975

 

Posted by 1010