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 - SQL Tutorial
From the course: Complete Guide to SQL for Data Engineering: from Beginner to Advanced
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,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Introduction to analytical functions5m 31s
-
(Locked)
Using the RANK() function7m 16s
-
(Locked)
Using the DENSE_RANK() function4m 27s
-
(Locked)
Exploring the ROW_NUMBER() function6m 35s
-
(Locked)
Understanding the LAG() and LEAD() functions7m 55s
-
(Locked)
Running totals with SUM() OVER()7m 29s
-
(Locked)
Calculating moving averages7m 33s
-
(Locked)
Challenge: Find out the sum33s
-
(Locked)
Solution: Find out the sum44s
-
(Locked)
-
-
-
-
-
-
-