From the course: Complete Guide to SQL for Data Engineering: from Beginner to Advanced

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Using the RANK() function

Using the RANK() function

- [Instructor] RANK function in PostgreSQL is a window function that assigns a rank to each row within a partition of a result set. The rank of a row is one plus the number of ranks that comes before it. For example, like in an school, or in your college when you have an exam and the exam results go out, based on the marks every student get, there is a rank assigned to each of these student. Similarly, in the SQL world also, when you are trying to analyze something and based on your need, you want to rank something, there a RANK function can be utilized. It is particularly useful in the scenarios where you want to compare items across some ordered groups. Let us see how RANK function works. RANK assigns a unique rank to each row. Maybe you decide the order, let's say, for example, if we talk about our product table. Now, in the product table, if I want to identify the product ranks based on the amount of this product,…

Contents