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...