Autoincrement value in a SELECT statement

From: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Autoincrement value in a SELECT statement
Date: 2016-08-20 22:44:45
Message-ID: CAAY=A78V4h_iyy-_Yq+0jDiu+GzNMXLP3adgfd=EuwZM5GyOiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

Let's suppose that I have a table like this:

team_name varchar(120)
score integer

I have a "SELECT team_name, score FROM teams ORDER BY score DESC". This
mean that the first position belongs to the highest score, second position
to the next score, and so on.What I need is to have the position.

position 1 for the highesst score
position 2 for the next score
.
.
.

Is it possible to include a field in the SELECT statement which "kind of
autoincrements" so I can get the position?

Respectfully,
Jorge Maldonado

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2016-08-21 00:09:56 Re: Autoincrement value in a SELECT statement
Previous Message Herby Raynaud 2016-07-20 21:55:34 Wiindow Aggregate function