PostgreSQL: How to calculate RANK in a query (DENSE_RANK())

In the PostgreSQL, You can also calculate RANK of a query using available windows functions.
Like SQL Server, PostgreSQL also provides functions like: RANK(), DENSE_RANK().

I am sharing one demonstration on calculating RANK of students bases on their marks. I require top 3 students result where more than one student has same marks.

Create a table with sample data:

Using DENSE_RANK(), Calculate RANK of students:

The Result:


Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

Be the First to Comment!

Notify of
avatar

wpDiscuz