Received: from mail.interchange.ca (ns.interchange.ca [216.126.79.2]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5BJ3ZE46779 for ; Mon, 11 Jun 2001 15:03:35 -0400 (EDT) (envelope-from michael@fastmail.ca) Received: by mail.interchange.ca (Fastmailer, from userid 555) id 7BF3F213F; Mon, 11 Jun 2001 15:03:29 -0400 (EDT) MIME-Version: 1.0 Message-Id: <3B251601.000107.67770@frodo.searchcanada.ca> To: tgl@sss.pgh.pa.us Subject: Re: finding a maximum or minimum sum Cc: pgsql-sql@postgresql.org From: "Michael Richards" X-Fastmail-IP: 24.43.130.237 Date: Mon, 11 Jun 2001 15:03:29 -0400 (EDT) Content-Transfer-Encoding: 7bit Content-Type: Text/Plain X-Archive-Number: 200106/169 X-Sequence-Number: 3392 Puuuurfect! This is exactly what I needed. Didn't know postgres supported subselects like that. Thanks. -Michael > select min(amtsum), max(amtsum), avg(amtsum) > from (select sum(amount) as amtsum from payments group by userid) > ss; > > In prior versions you'd need to do the initial select into a temp > table and then select min/max/avg from that. _________________________________________________________________ http://fastmail.ca/ - Fast Free Web Email for Canadians From pgsql-sql-owner@postgresql.org Mon Jun 11 19:24:18 2001 Received: from bubbles.electricutopia.net (bubbles.electricutopia.net [63.214.178.76]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5BNOFE37903; Mon, 11 Jun 2001 19:24:15 -0400 (EDT) (envelope-from dave@slickness.org) Received: from localhost (dave@localhost) by bubbles.electricutopia.net (8.9.3/8.9.3) with ESMTP id QAA03026; Mon, 11 Jun 2001 16:23:29 -0700 Date: Mon, 11 Jun 2001 16:23:29 -0700 (PDT) From: David Olbersen X-X-Sender: To: =?iso-8859-1?q?Mart=EDn=20Marqu=E9s?= cc: pgsql sql Mailing List , Subject: Re: ORDER BY what? In-Reply-To: <01061111193103.29653@bugs> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from QUOTED-PRINTABLE to 8bit by postgresql.org id f5BNOGE37905 X-Archive-Number: 200106/170 X-Sequence-Number: 3393 On Mon, 11 Jun 2001, Martín Marqués wrote: > My question is: "How can I write an ORDER BY statment so that it's ordered by > the amount of matches it gets?" Your question is a bit unclear, what is "it"? Specifically, what are the "it's" that are to be ordered, and which "it" gets matches? -- Dave