Received: from linux.akadine.com (linux.akadine.com [208.217.232.5]) by hub.org (8.10.1/8.10.1) with ESMTP id e6KG1Fh61415 for ; Thu, 20 Jul 2000 12:01:15 -0400 (EDT) Received: from db.akadine.com (babel.akadine.com [208.217.232.250]) by linux.akadine.com (8.9.3/8.9.3) with ESMTP id MAA16376 for ; Thu, 20 Jul 2000 12:02:30 -0400 Date: Thu, 20 Jul 2000 12:02:30 -0400 (EDT) From: John To: pgsql-sql@postgresql.org Subject: Nested Aggregates? Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200007/194 I know nested aggregates aren't allowed, or at least not implicitly. Is there a way to get around this.? Or does someone feel like droppng some other hints this way? Problem : (not really) I have a table (id, date, ordertype, etc...) Based on the type i want to be able to get the counts of how many people have ordered from a certain type of ordertype. so i. select id, count(*) as cnt from T1 where ordertype = 'Q' group by id; This will give me the number of times each id has ordered type Q. I need a way to find out how many times, or how many ids have ordered type Q once, twice, thrice, etc. I can accomplish this by doing a select into temp with the above statement. And then doing. Select cnt, count(*) from TEMP group by cnt; This really doesn't seem the most efficient way to do this by me. And i know nested aggs aren't allowed (or don't like me). And i'm trying to fidn a way to eliminate the insert / select step. so the main question is. how do i accomplish ths better? can anyone help? and how can i implement it as a subselect that will work? will that be more efficient. Sorry if the question's seem simple / trivial. But it's been gnawing at me for a while that this doesn't seem to be the most efficient way to handle this select. And i can't figure out another way that postgres will accept. Thanks in advance. .jtp