Oracle分析函數ntile,oracle函數ntile

來源:互聯網
上載者:User

Oracle分析函數ntile,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行。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.