Skip to content
Advertisement

Redshift Postgres 8

I’m trying to write a query to solve a logical problem using Redshift Postgres 8.

Input column is a bunch of Order IDs and Step Group IDs and desired output is basically a sequence of the IDs as you can see in the screenshot.

If you could help me answer this question, that would be great, thanks!

https://i.stack.imgur.com/bU3j7.png

This is a follow up question from SQL Server – logical question – Get rank from IDs

Advertisement

Answer

Assuming you want to partition the table by the first two columns and then to number the rows in each partition, you can use this query:

SELECT *, ROW_NUMBER() OVER (PARTITION BY order_item_id, id ORDER BY order_item_id, id) FROM table;
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement