Oracle Rank () over () __oracle

Source: Internet
Author: User

Rank () Use description:

A. Introduction to Functions:

Returns the rank of the value of the specified field within the result set partition, and the value of the specified field is ranked before the related row plus one.

B. Grammar:

RANK () over ([<partiton_by_clause>]<order by Clause>)

C. Parameter Description:

Partition_by_clause The result set that is generated from the FROM clause into the partition applied to the rank function.

Order_by_clause determines the order in which the rank value is applied to rows in the partition.

D. The following are examples of use:

1. Create a test table

  SQL code   --Creating tables   -- create table   Create table t_score    (     AUTOID   NUMBER not null,      s_id     number (3),     s_name   char (8)  not null,     sub_name varchar2 (,  )   SCORE     number (10,2)   );  -- add comments to the table     comment on table t_score     is  ' student performance form ';  - - add comments to the columns    Comment on column t_ SCORE. autoid     is  ' primary key ID ';   Comment on column t_score. s_id     is  ' student ID ';   comment on column t_score. s_name     is  ' student name ';   Comment on column t_score. sub_name     is  ' subject ';   comment on column t_score. score     is  ' Results ';  

2. Create a Test record

  SQL code    insert into t_score  (Autoid, s_id, s_name, sub_name,  score)    values  (8, 1,  ' John      ',  ' language ',  80.00);       insert into t_score  (Autoid, s_id, s_name, sub_name,  score)    values  (9, 2,  ' Dick      ',  ' mathematics ',  80.00);       insert into t_score  (Autoid, s_id, s_name, sub_name,  score)    values  (10, 1,  ' John      ',  ' mathematics ',  0.00);       insert into t_score  (Autoid, s_id, s_name, sub_name,  score)    values  (11, 2,  ' Dick      ',  ' language ',  50.00);       insert into t_score  (Autoid, s_id, s_name, sub_name,  score)    values  (12, 3,  ' Zhang    ',  ' languages ',  10.00);      Insert into  t_score  (Autoid, s_id, s_name, sub_name, score)    values  (13,  3,  ' Zhang    ',  ' mathematics ',  null);      Insert into t_score   (Autoid, s_id, s_name, sub_name, score)    values  (14, 3,  ' Zhang    ',  ' Sports ',  120.00);      insert into t_score  (autoid,  s_id, s_name, sub_name, score)    values  (15, 4,  ' Yang over       ',  ' 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,  ' Zhang    ',  ' Oracle ')  0.00);      insert into t_score  (autoid, s_id, s_name,  Sub_name, score)    values  (4, 4,  ' Yang over      ',  ' Oracle ',  77.00);      insert into t_score  (autoid, s_id, s_name,  Sub_name, score)    values  (17, 2,  ' Dick      ',  ' Oracle ')  77.00);  

3. Query in different circumstances

3.1 Check all the students ' grades

SQL code--1. Check all the students ' grades

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.