From the course: PostgreSQL: Advanced Queries

Unlock the full course today

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

Solution: Calculations across rows

Solution: Calculations across rows - PostgreSQL Tutorial

From the course: PostgreSQL: Advanced Queries

Solution: Calculations across rows

(bright music) - [Instructor] In this final challenge, we were asked to sort people by height and then figure out how much taller each person is over the next person in the sequence. Let's run the starting query, and we'll see that we get a list of names and each person's height in US inches. Now the very first thing that we need to do is to sort everyone tallest to shortest. And that just needs the addition of an order by clause to the end of the query here. So we'll say order by height_inches. And I want to make sure everybody is ordered descending so we get the tallest person here at the very top. Okay, so we can now see that Marcellus is the tallest person at 76.87, followed by Steph at 74.74. And I want to focus on these two people here. It'll help us out as we move through the rest of the challenge. Okay, so now everyone is in height order. Now we need to add in a column that says that Marcellus is taller than Steph. And we can do that by pulling out the name column and then…

Contents