3
I want to make a SELECT with some existing columns in the database and add a ordered numerical column starting at 1 for each line (I don’t want the ID). I’m using Postgresql 8.4.
Example:
SELECT
descricao_produto,
preco,
colunaDinamicaOrdenada AS ordem
FROM produtos;
Where colunaDinamicaOrdenada
would be a command, subselect or something of the kind that forms a sequence of ordered numbers starting at 1.
Desired result:
descricao_produto | preco | ordem
Maçã 5,90 1
Banana 4,00 2
Melancia 7,00 3
Laranja 3,00 4
Guy this
row_number()
was what I needed to do this and ended up helping me A LOT in other commands that I needed to do then, thanks! I didn’t even know about thosewindow functions
– Edson Horacio Junior