Oracle分析函数ntile
有这么一个需求,将课程的成绩分成四个等级,为学生打A、B、C、D的绩效。
drop table course purge;
create table course
(
id number,
grade number
);
insert into course values(1,50);
insert into course values(2,55);
insert into course values(3,60);
insert into course values(4,65);
insert into course values(5,70);
insert into course values(6,75);
insert into course values(7,80);
insert into course values(8,85);
insert into course values(9,90);
insert into course values(10,95);
commit;
SQL> select id,grade,ntile(4) over(order by grade desc) til from course;
ID GRADE TIL
---------- ---------- ----------
10 95 1
9 90 1
8 85 1
7 80 2
6 75 2
5 70 2
4 65 3
3 60 3
2 55 4
1 50 4
已选择10行。
在CentOS 6.4下安装Oracle 11gR2(x64)