agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedAutoincrement value in a SELECT statement
2+ messages / 2 participants
[nested] [flat]
* Autoincrement value in a SELECT statement
@ 2016-08-20 22:44 JORGE MALDONADO <jorgemal1960@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: JORGE MALDONADO @ 2016-08-20 22:44 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Autoincrement value in a SELECT statement
@ 2016-08-21 00:09 Tom Lane <tgl@sss.pgh.pa.us>
parent: JORGE MALDONADO <jorgemal1960@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2016-08-21 00:09 UTC (permalink / raw)
To: JORGE MALDONADO <jorgemal1960@gmail.com>; +Cc: pgsql-sql
JORGE MALDONADO <jorgemal1960@gmail.com> writes:
> Is it possible to include a field in the SELECT statement which "kind of
> autoincrements" so I can get the position?
The row_number() window function should do that for you, or you might
want rank() depending on what you think should happen for ties.
regards, tom lane
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2016-08-21 00:09 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-08-20 22:44 Autoincrement value in a SELECT statement JORGE MALDONADO <jorgemal1960@gmail.com>
2016-08-21 00:09 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox