![]() RANK() OVER( ORDER BY marks ASC) as studs_rankįROM marks Code language: SQL (Structured Query Language) ( sql ) Ranking Students Lowest FirstĪs you can see, ranks are assigned in the lowest-first fashion. We can also rank them by lowest first order using the ASC order. Here we have ranked the students with the highest marks on the top. RANK() OVER( ORDER BY marks DESC) as studs_rankįROM marks Code language: SQL (Structured Query Language) ( sql ) Ranking Students Highest FirstĪs you can see here- we didn’t get the consecutive ranking for the next immediate groups. However, the next individual or a group of students having the same marks will not get the immediate ranking to the previous rank. Note that, if two or more students have the same marks, then they will get the same ranking. Now we will write a query using the RANK() function to assign the rankings to the students from all divisions. SELECT * FROM marks Code language: SQL (Structured Query Language) ( sql ) Marks Table Data ![]() Let’s display the table data to check if the values are correctly inserted. ![]() ) Code language: SQL (Structured Query Language) ( sql ) INSERT INTOmarks( name, class, marks) VALUES We will create a table to store the names and marks of students from different divisions.
0 Comments
Leave a Reply. |