From: missive@frontiernet.net
To: pgsql-sql@postgresql.org
Subject: Re: Number the lines
Date: Sat, 15 Sep 2001 03:12:26 +0000 (UTC)
Message-ID: <9nugup$20cg$1@news.tht.net> (raw)
References: <70c8063b.0109140405.1895bf0d@posting.google.com>
On 14 Sep 2001 05:05:49 -0700, Yoann <yaubi@yaubi.com> wrote:
> how can I number the result's lines of a sql query ?
>
> explaination : I have a query which return me a list of values. I need
> to order them (it's ok, easy ;) and then number the lines. The goal is
> then to extract, for example, "the third maximum value".
>
CREATE TABLE value (i integer);
INSERT INTO i VALUES (1);
INSERT INTO i VALUES (3);
INSERT INTO i VALUES (2);
INSERT INTO i VALUES (1);
INSERT INTO i VALUES (5);
INSERT INTO i VALUES (2);
CREATE VIEW ordered AS SELECT i FROM value ORDER BY i DESC;
BEGIN;
CREATE SEQUENCE seq;
SELECT nextval('seq') as n, i INTO TEMP TABLE t FROM ordered;
SELECT i FROM t WHERE n=3;
-- IANADBA, but something like this might work...
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: missive@frontiernet.net
Subject: Re: Number the lines
In-Reply-To: <9nugup$20cg$1@news.tht.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox