X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B4A6953598 for ; Thu, 31 Mar 2005 04:01:30 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53466-06 for ; Thu, 31 Mar 2005 03:01:23 +0000 (GMT) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.203]) by svr1.postgresql.org (Postfix) with ESMTP id B365F53485 for ; Thu, 31 Mar 2005 04:01:20 +0100 (BST) Received: by rproxy.gmail.com with SMTP id j1so265832rnf for ; Wed, 30 Mar 2005 19:01:24 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=sMp95Zkkaqy1YFqbYlFiZfOgW85f8HGlQDeWbujpQxCuk8qt7JbjlLddCZeUn5KpIV6O0vJYt2ODadiQ9w4hrQdhd9xisI0VU+rnB3mASFsreBjZLXIq/clfhg8Ma7vfjCDV5P7g9/VF2sexXDW2n20BYxj/Ryv6BuJfgDmWQBc= Received: by 10.38.75.70 with SMTP id x70mr1060292rna; Wed, 30 Mar 2005 19:01:24 -0800 (PST) Received: by 10.38.97.29 with HTTP; Wed, 30 Mar 2005 19:01:24 -0800 (PST) Message-ID: Date: Wed, 30 Mar 2005 22:01:24 -0500 From: Jaime Casanova Reply-To: Jaime Casanova To: =?UTF-8?B?5p6X77+9W+mLhQ==?= Subject: Re: A SQL Question About distinct, limit, group by, having, aggregate Cc: pgsql-sql@postgresql.org In-Reply-To: <20050331022422.M58459@cyut.edu.tw> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable References: <20050331022422.M58459@cyut.edu.tw> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.282 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200503/404 X-Sequence-Number: 20883 On Thu, 31 Mar 2005 10:29:16 +0800, "=E6=9E=97=EF=BF=BD[=E9=8B=85" wrote: > i have a little question, how to get 3 higher score student in every clas= s. > Data looks like as below >=20 > problem: > id=09=09class=09=09score > john=09=09a=09=09100 > jenny=09=09a=09=0970 > ken=09=09a=09=0959 > mary=09=09b=09=0985 > jacky=09=09b=09=0980 > lily=09=09b=09=0970 > kevin=09=09b=09=0950 > david=09=09b=09=0930 > tina=09=09c=09=0985 > tony=09=09c=09=0980 > bare=09=09c=09=0970 > vivian=09=09c=09=0960 > eric=09=09c=09=0957 > andy=09=09c=09=0950 >=20 > result: > id=09=09class=09=09score > john=09=09a=09=09100 > jenny=09=09a=09=0970 > ken=09=09a=09=0959 > mary=09=09b=09=0985 > jacky=09=09b=09=0980 > lily=09=09b=09=0970 > tina=09=09c=09=0985 > tony=09=09c=09=0980 > bare=09=09c=09=0970 >=20 Actually, i don't see any difference between problem and results but maybe select * from yourTable order by class, score desc regards, Jaime Casanova