From: | Patrik Kudo <kudo(at)partitur(dot)se> |
---|---|
To: | Yoann <yaubi(at)yaubi(dot)com> |
Cc: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Which SQL query makes it possible to optain the 3 greatest |
Date: | 2001-09-15 00:11:36 |
Message-ID: | Pine.BSF.4.31.0109150208350.43402-100000@tb303.partitur.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 12 Sep 2001, Yoann wrote:
> OO( Sql Problem )Oo.
>
> That is to say a table of 5 inputs of 1 integer field :
>
> Table = { (1); (12); (3); (9); (4) }
Am I right that what you have is this?
CREATE TABLE T (v integer);
INSERT INTO T (v) VALUES (1);
INSERT INTO T (v) VALUES (12);
INSERT INTO T (v) VALUES (3);
INSERT INTO T (v) VALUES (9);
INSERT INTO T (v) VALUES (4);
In that case you could do the following:
SELECT v FROM T ORDER BY v DESC LIMIT 3;
This will select the values, sort them in descending order and limit the
result to 3 rows.
I hope it helps.
Regards,
Patrik Kudo
> We want to obtain a result of 1 input of 3 fields,
> corresponding to the 3 greatest values of Table,
> by descending order :
>
> Result = { (12; 9; 4) }
>
> => Which SQL query makes it possible to obtain Result from Table ?
> We certainly need to use sub-queries, but how ?
>
> Thank you in advance for your help !
>
> Yoann AUBINEAU
From | Date | Subject | |
---|---|---|---|
Next Message | ke wang | 2001-09-15 00:35:11 | How to see the definition of an existing table? |
Previous Message | Wei Weng | 2001-09-15 00:08:09 | Re: Which SQL query makes it possible to optain the 3 greatest values of an interger list ? |