From the course: PostgreSQL: Advanced Queries
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Find a hypothetical rank - PostgreSQL Tutorial
From the course: PostgreSQL: Advanced Queries
Find a hypothetical rank
- [Instructor] Using rank and dense rank as a window function with an OVER clause will add numeric rankings in line with your other data columns. You can also use rank and dense rank as an ordered set function within a group. This will allow you to answer hypothetical questions. Now you may be wondering, "What exactly is a hypothetical question?" With this technique, we could get rankings for values that don't actually exist within the data and find out, hypothetically speaking, where they would rank if they were in the dataset. I think an example will help clarify what I mean. Let's take a look at the height data again. I'll select the name and height inches columns from the people heights table and we'll sort the data descending. So here's the data that's currently stored in the database. Marcellus is the tallest person at 76.87 inches tall. The second tallest person is Steph at 74.74 inches. Now, let's suppose that we…
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.