有這麼一個需求,將課程的成績分成四個等級,為學生打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行。