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