Re: Number the lines

From: missive(at)frontiernet(dot)net (Lee Harr)
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Number the lines
Date: 2001-09-15 03:12:26
Message-ID: 9nugup$20cg$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 14 Sep 2001 05:05:49 -0700, Yoann <yaubi(at)yaubi(dot)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...

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andre Schnabel 2001-09-15 07:47:28 Re: To query many tables.
Previous Message ke wang 2001-09-15 00:35:11 How to see the definition of an existing table?