From the course: PostgreSQL: Advanced Queries

Unlock the full course today

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

Rank rows with a window function

Rank rows with a window function - PostgreSQL Tutorial

From the course: PostgreSQL: Advanced Queries

Rank rows with a window function

- [Instructor] Putting values in sequential order and ranking data rows is a very common analysis operation. Ranking data is how you determine which products sell the best and which ones are underperforming. Or which items are the largest, tallest, heaviest, or most expensive and which items are the smallest, shortest, lightest, or least expensive. We rank things from top to bottom all the time. In PostgreSQL, the rank function can be used in a couple of different ways depending on the kinds of questions that you're looking to answer. It can be used as a window function to provide context in line with your data rows or it can be used as an ordered set grouping function to answer hypothetical questions. First, I want to look at using rank as a window function. Remember that window functions use the over clause and don't require a group by clause in the query. I'm going to pull the name and height_inches column from the…

Contents