From the course: PostgreSQL: Advanced Queries
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Output row numbers with query results - PostgreSQL Tutorial
From the course: PostgreSQL: Advanced Queries
Output row numbers with query results
- [Instructor] When you execute a query, depending on the graphical interface you're working with, you'll typically have a list of numbers down the left side of the results that indicate each rows number. For instance, if I select all of the product data, when I execute the query here in PGAdmin, the left of the data output grid shows each row's position in the results. These numbers aren't part of the actual data. They're just shown as a convenience here in the graphical interface. However, PostgreSQL does have a row number as function that'll add this kind of sequence number as a column in the result set, which makes it convenient if you want to export the data to a spreadsheet or incorporate it into a report. To add a column of row numbers, first, select your table columns as usual, then we'll create a column using the row number function. This is a window function, so it needs an over clause. That creates an…
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)
Output row numbers with query results2m 29s
-
(Locked)
Cast values to a different data type2m 15s
-
(Locked)
Move rows within a result with LEAD and LAG5m 47s
-
(Locked)
Use an IN function with a subquery4m 7s
-
(Locked)
Define WHERE criteria with a series4m 30s
-
(Locked)
Solution: Calculations across rows4m 19s
-
(Locked)
Pattern matching with regular expressions6m 57s
-
(Locked)
-