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 269343A3B31 for ; Wed, 19 Jan 2005 03:11:39 +0000 (GMT) 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 09033-04 for ; Wed, 19 Jan 2005 03:11:30 +0000 (GMT) Received: from smtp.ford-prefect.net (dsl081-233-106.lax1.dsl.speakeasy.net [64.81.233.106]) by svr1.postgresql.org (Postfix) with ESMTP id 1AAA83A3B08 for ; Wed, 19 Jan 2005 03:11:33 +0000 (GMT) Received: from amd1700 ([192.168.0.2]) by smtp.ford-prefect.net (8.12.11/8.12.11) with ESMTP id j0J3BUwI029398; Tue, 18 Jan 2005 19:11:31 -0800 From: "Bob" To: PFC , pgsql-sql@postgresql.org Date: Tue, 18 Jan 2005 19:11:30 -0800 MIME-Version: 1.0 Subject: Re: "How do I ..." SQL question Message-ID: <41ED5F62.1270.30449FEC@localhost> In-reply-to: References: <31958303.1106004700938.JavaMail.root@dewey.psp.pas.earthlink.net> X-mailer: Pegasus Mail for Windows (4.21c) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200501/220 X-Sequence-Number: 20008 PFC wrote: > Return only four rows beginning at second row: > > > > SELECT count(*) AS count, name, year FROM a > > GROUP BY name, year > > ORDER BY count DESC, name ASC > > LIMIT 4 OFFSET 1; > > > > count name year > > ------- ------ ------ > > 3 joe 2004 s,e,e > > 2 bob 2003 w,e > > 2 kim 2003 s,s > > 2 sue 2004 s,w > > > > Select only places visited included in LIMITed query: > > > Is this : > > SELECT DISTINCT place FROM a,( > SELECT count(*) AS count, name, year FROM a > GROUP BY name, year > ORDER BY count DESC, name ASC > LIMIT 4 OFFSET 1 > ) as foo WHERE name=foo.name AND year=foo.year > > Problem with this approach is that you'll have to run the query twice, > one to get the hitlist by user, one for the places... > > > > > SELECT DISTINCT place FROM a ????; > > > > place > > ------- > > south > > west > > east Thanks, this worked. As it happens, I am already creating a temporary table for the hitlist for other uses so that isn't a problem. -Bob