Re: Number the lines - Mailing list pgsql-sql

From missive@frontiernet.net (Lee Harr)
Subject Re: Number the lines
Date
Msg-id 9nugup$20cg$1@news.tht.net
Whole thread Raw
In response to Number the lines  (yaubi@yaubi.com (Yoann))
List pgsql-sql
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...



pgsql-sql by date:

Previous
From: Hans-Juergen Schoenig
Date:
Subject: Re: How to Get Timestamp From SECONDS?
Next
From: Hans-Juergen Schoenig
Date:
Subject: Re: Checking for table existence