Oracle Rank() Over()__Oracle

來源:互聯網
上載者:User

Rank()使用說明:

 

a. 函數簡介:

    返回結果集分區內指定欄位的值的排名,指定欄位的值的排名是相關行之前的排名加一。

b. 文法:

    RANK() OVER([<partiton_by_clause>]<order by clause>)

c. 參數說明:

    partition_by_clause 將from子句產生的結果集劃分為應用到RANK函數的分區。

    Order_by_clause確定將RANK值應用到分區中的行時所使用的順序。

d. 以下是執行個體使用:

 

 

1. 建立測試表

  Sql代碼    --建立表   -- Create table   create table T_SCORE   (     AUTOID   NUMBER not null,     S_ID     NUMBER(3),     S_NAME   CHAR(8) not null,     SUB_NAME VARCHAR2(20),     SCORE    NUMBER(10,2)   );   -- Add comments to the table    comment on table T_SCORE     is '學產生績表';   -- Add comments to the columns    comment on column T_SCORE.AUTOID     is '主鍵ID';   comment on column T_SCORE.S_ID     is '學生ID';   comment on column T_SCORE.S_NAME     is '學生姓名';   comment on column T_SCORE.SUB_NAME     is '科目';   comment on column T_SCORE.SCORE     is '成績';  

 

2. 建立測試記錄

  Sql代碼    insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (8, 1, '張三    ', '語文', 80.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (9, 2, '李四    ', '數學', 80.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (10, 1, '張三    ', '數學', 0.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (11, 2, '李四    ', '語文', 50.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (12, 3, '張三丰  ', '語文', 10.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (13, 3, '張三丰  ', '數學', null);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (14, 3, '張三丰  ', '體育', 120.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (15, 4, '楊過    ', 'JAVA', 90.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (16, 5, 'mike    ', 'c++', 80.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (3, 3, '張三丰  ', 'Oracle', 0.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (4, 4, '楊過    ', 'Oracle', 77.00);      insert into t_score (AUTOID, S_ID, S_NAME, SUB_NAME, SCORE)   values (17, 2, '李四    ', 'Oracle', 77.00);  

 

3. 分不同情況查詢

3.1 查詢所有的學產生績

  Sql代碼    --1.查詢所有的學產生績  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.