In order to Provide example of Rank () function I need sample data, here we are using “Student” table. This table consists of two Column ‘Name’ and ‘ToltalMark’. Below is Sql query for Creating and Populating Student table.
SET NOCOUNT ON CREATE TABLE Student( FirstName VARCHAR(20), Mark INT ) INSERT INTO Student VALUES ('Sree Hari',23) INSERT INTO Student VALUES ('Sajid',40) INSERT INTO Student VALUES ('George',6) INSERT INTO Student VALUES ('Mary',11) INSERT INTO Student VALUES ('Sam',17) INSERT INTO Student VALUES ('Jafar',6) INSERT INTO Student VALUES ('Babu',38) INSERT INTO Student VALUES ('Larry',5) INSERT INTO Student VALUES ('Malu',29) INSERT INTO Student VALUES ('Nisha',49) INSERT INTO Student VALUES ('Biju',23)
The RANK function use is given below
SELECT RANK() OVER (ORDER BY Mark DESC) AS [Rank], FirstName, Mark FROM student
|
No responses found. Be the first to respond and make money from revenue sharing program.
|